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.preference.IPreferenceKeys;
-import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
/**
* @author pplitzner
private Text text_title;
private Button btnOpenFeatureTree;
private TreeViewer viewer;
- private Button btnAdd;
- private Button btnRemove;
- private Button btnExportTree;
-
- private Composite composite_buttons;
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.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
text_title.setEnabled(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_buttons = new Composite(this,
- SWT.NULL);
- composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
- false));
- composite_buttons.setLayout(new GridLayout());
-
- btnAdd = new Button(composite_buttons, SWT.PUSH);
- btnAdd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- btnAdd.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
- btnAdd.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
- btnRemove = new Button(composite_buttons, SWT.PUSH);
- btnRemove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- btnRemove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
- btnRemove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
-
- btnExportTree = new Button(composite_buttons, SWT.NONE);
- btnExportTree.setToolTipText("Export feature tree");
- btnExportTree.setImage(ImageResources.getImage(ImageResources.MOVE_ICON));
- btnExportTree.setVisible(TaxeditorStorePlugin.getDefault().getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES));
-
- setButtonsEnabled(false);
+ public void init(String label, DragSourceListener dragSourceListener, DropTargetListener dropTargetListener,
+ ISelectionChangedListener viewerSelectionChangedListener, IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ this.init(label, dragSourceListener, dropTargetListener, viewerSelectionChangedListener, null, dirtyMarkable,
+ textModifyListener);
+ }
+ public void init(DragSourceListener dragSourceListener, DropTargetListener dropTargetListener,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ SelectionListener openFeatureTreeSelectionListener,
+ ModifyListener textModifyListener) {
+ init(null, dragSourceListener, dropTargetListener, viewerSelectionChangedListener, openFeatureTreeSelectionListener,
+ null, textModifyListener);
}
+ private void init(String label, DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ SelectionListener openFeatureTreeSelectionListener, IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ if(label!=null){
+ label_title.setText(label);
+ }
- public void init(DragSourceListener dragSourceListener,
- DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
- SelectionListener openFeatureTreeSelectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener, SelectionListener exportButtonSelectionListener) {
viewer.setContentProvider(new FeatureTreeContentProvider());
viewer.setLabelProvider(new FeatureTreeLabelProvider());
int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
- .getInstance() };
+ .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);
+ }
- btnAdd.addSelectionListener(addButtonSelectionListener);
- btnRemove.addSelectionListener(removeButtonSelectionListener);
- btnExportTree.addSelectionListener(exportButtonSelectionListener);
+ 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);
+ text_title.setEnabled(false);
+ 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);
- getText_title().setEnabled(true);
- setButtonsEnabled(true);
+ 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);
+ }
+ text_title.setEnabled(true);
text_title.setEnabled(true);
}
- private void setButtonsEnabled(boolean enabled){
- btnAdd.setEnabled(enabled);
- btnRemove.setEnabled(enabled);
- btnExportTree.setEnabled(enabled);
- }
-
- /**
- * @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 Label getLabel_title() {
+ return label_title;
+ }
+
public Button getBtnOpenFeatureTree() {
return btnOpenFeatureTree;
}
- /**
- * @return the viewer
- */
public TreeViewer getViewer() {
return viewer;
}
- /**
- * @return the button_add
- */
- public Button getBtnAdd() {
- return btnAdd;
- }
-
- /**
- * @return the button_remove
- */
- public Button getBtnRemove() {
- return btnRemove;
- }
-
- /**
- * @return the composite_buttons
- */
- public Composite getComposite_buttons() {
- return composite_buttons;
- }
-
- /**
- * @return the btnExportTree
- */
- public Button getBtnExportTree() {
- return btnExportTree;
- }
-
}