import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
/**
* @author pplitzner
private Text text_title;
private Button btnOpenFeatureTree;
private TreeViewer viewer;
- private Button button_add;
- private Button button_remove;
public FeatureTreeEditorComposite(Composite parent, int style) {
super(parent, style);
- setLayout(new GridLayout(2, false));
+ setLayout(new GridLayout(1, false));
Composite composite_treeTitle = new Composite(this, SWT.NULL);
composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
false));
- GridLayout gl_composite_treeTitle = new GridLayout(2, false);
+ GridLayout gl_composite_treeTitle = new GridLayout(3, false);
gl_composite_treeTitle.marginWidth = 0;
composite_treeTitle.setLayout(gl_composite_treeTitle);
text_title = new Text(composite_treeTitle, SWT.BORDER);
text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ text_title.setEditable(false);
- btnOpenFeatureTree = new Button(this, SWT.NONE);
+ btnOpenFeatureTree = new Button(composite_treeTitle, SWT.NONE);
btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
btnOpenFeatureTree.setToolTipText(Messages.FeatureTreeEditorComposite_OPEN_TREE);
btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
- viewer = new TreeViewer(this);
+ viewer = new TreeViewer(new Tree(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI));
Tree tree = viewer.getTree();
- tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
viewer.getControl().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
-
- Composite composite_buttons = new Composite(this,
- SWT.NULL);
- composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
- false));
- composite_buttons.setLayout(new GridLayout());
-
- button_add = new Button(composite_buttons, SWT.PUSH);
- button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- button_add.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
- button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
- button_remove = new Button(composite_buttons, SWT.PUSH);
- button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- button_remove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
- button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
}
+ public void init(String label,
+ DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ this.init(label,
+ dragSourceListener,
+ dropTargetListener,
+ null,
+ viewerSelectionChangedListener,
+ null,
+ dirtyMarkable,
+ textModifyListener);
+ }
public void init(DragSourceListener dragSourceListener,
- DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
- SelectionListener openFeatureTreeSelectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
+ DropTargetListener dropTargetListener,
+ Transfer[] transfers,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ SelectionListener openFeatureTreeSelectionListener,
+ ModifyListener textModifyListener) {
+ init(null, dragSourceListener,
+ dropTargetListener,
+ transfers,
+ viewerSelectionChangedListener,
+ openFeatureTreeSelectionListener,
+ null,
+ textModifyListener);
+ }
+ private void init(String label, DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
+ Transfer[] transfers,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ SelectionListener openFeatureTreeSelectionListener,
+ IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ if(label!=null){
+ label_title.setText(label);
+ }
+
viewer.setContentProvider(new FeatureTreeContentProvider());
viewer.setLabelProvider(new FeatureTreeLabelProvider());
int ops = DND.DROP_COPY | DND.DROP_MOVE;
- Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
- .getInstance() };
+ if(transfers==null){
+ transfers = new Transfer[] {
+ FeatureNodeTransfer.getInstance(),
+ TermTransfer.getInstance(),
+ };
+ }
if(dragSourceListener!=null){
viewer.addDragSupport(ops, transfers, dragSourceListener);
}
viewer.addDropSupport(ops, transfers, dropTargetListener);
}
- viewer.addSelectionChangedListener(viewerSelectionChangedListener);
+ if(viewerSelectionChangedListener!=null){
+ viewer.addSelectionChangedListener(viewerSelectionChangedListener);
+ }
- button_add.addSelectionListener(addButtonSelectionListener);
- button_remove.addSelectionListener(removeButtonSelectionListener);
+ if(textModifyListener!=null){
+ text_title.addModifyListener(textModifyListener);
+ }
- btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
+ //add specific selection listener
+ if(openFeatureTreeSelectionListener!=null){
+ btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
+ }
+ else{
+ //add default selection listener
+ btnOpenFeatureTree.addSelectionListener(new SelectionAdapter(){
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FeatureTree tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
+ null);
+ if(tree!=null){
+ setSelectedTree(tree);
+ if(dirtyMarkable!=null){
+ dirtyMarkable.forceDirty();
+ }
+ }
+ }
+ });
+ }
}
- public void setSelectedTree(FeatureTree featureTree, ModifyListener modifyListener) {
+ public void setSelectedTree(FeatureTree featureTree) {
this.featureTree = featureTree;
- getViewer().setInput(featureTree);
+ viewer.setInput(featureTree);
- getText_title().removeModifyListener(modifyListener);
- getText_title().setText(featureTree.getTitleCache());
- getText_title().addModifyListener(modifyListener);
+ Listener[] listeners = text_title.getListeners(SWT.Modify);
+ for (Listener listener : listeners) {
+ text_title.removeListener(SWT.Modify, listener);
+ }
+ text_title.setText(featureTree!=null?featureTree.getTitleCache():"");
+ for (Listener listener : listeners) {
+ text_title.addListener(SWT.Modify, listener);
+ }
}
- /**
- * @return the featureTree
- */
public FeatureTree getFeatureTree() {
return featureTree;
}
- /**
- * @return the label_title
- */
public Label getLabel_title() {
return label_title;
}
- /**
- * @return the text_title
- */
- public Text getText_title() {
- return text_title;
- }
-
- /**
- * @return the btnOpenFeatureTree
- */
public Button getBtnOpenFeatureTree() {
return btnOpenFeatureTree;
}
- /**
- * @return the viewer
- */
public TreeViewer getViewer() {
return viewer;
}
- /**
- * @return the button_add
- */
- public Button getButton_add() {
- return button_add;
- }
-
- /**
- * @return the button_remove
- */
- public Button getButton_remove() {
- return button_remove;
- }
-
}