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.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.model.term.TermTree;
+import eu.etaxonomy.cdm.model.term.TermType;
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.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
/**
* @author pplitzner
* @since Jun 19, 2017
- *
*/
-public class FeatureTreeEditorComposite extends Composite{
+public class FeatureTreeEditorComposite <T extends DefinedTermBase> extends Composite{
- private FeatureTree featureTree;
+ private TermTree<T> featureTree;
private Label label_title;
private Text text_title;
text_title = new Text(composite_treeTitle, SWT.BORDER);
text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- text_title.setEnabled(false);
+ text_title.setEditable(false);
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(new Tree(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+ 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, 3, 1));
viewer.getControl().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
}
- public void init(DragSourceListener dragSourceListener, DropTargetListener dropTargetListener,
+ public void init(String label,
+ DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
ISelectionChangedListener viewerSelectionChangedListener,
- SelectionListener openFeatureTreeSelectionListener) {
+ IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ init(label,
+ null,
+ dragSourceListener,
+ dropTargetListener,
+ null,
+ viewerSelectionChangedListener,
+ null,
+ dirtyMarkable,
+ textModifyListener);
+ }
+
+ public void init(String label, TermType termType,
+ DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ IDirtyMarkable dirtyMarkable,
+ ModifyListener textModifyListener) {
+ this.init(label,
+ termType,
+ dragSourceListener,
+ dropTargetListener,
+ null,
+ viewerSelectionChangedListener,
+ null,
+ dirtyMarkable,
+ textModifyListener);
+ }
+ public void init(DragSourceListener dragSourceListener,
+ DropTargetListener dropTargetListener,
+ Transfer[] transfers,
+ ISelectionChangedListener viewerSelectionChangedListener,
+ SelectionListener openFeatureTreeSelectionListener,
+ ModifyListener textModifyListener) {
+ init(null,
+ null,
+ dragSourceListener,
+ dropTargetListener,
+ transfers,
+ viewerSelectionChangedListener,
+ openFeatureTreeSelectionListener,
+ null,
+ textModifyListener);
+ }
+ private void init(String label,
+ TermType termType,
+ 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(), TermTransfer.getInstance() };
+ if(transfers==null){
+ transfers = new Transfer[] {
+ FeatureNodeTransfer.getInstance(),
+ TermTransfer.getInstance(),
+ };
+ }
if(dragSourceListener!=null){
viewer.addDragSupport(ops, transfers, dragSourceListener);
}
viewer.addSelectionChangedListener(viewerSelectionChangedListener);
}
+ if(textModifyListener!=null){
+ text_title.addModifyListener(textModifyListener);
+ }
+
//add specific selection listener
if(openFeatureTreeSelectionListener!=null){
btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
}
- //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, null);
- getText_title().setEnabled(false);
+ else{
+ //add default selection listener
+ btnOpenFeatureTree.addSelectionListener(new SelectionAdapter(){
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TermTree<T> tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
+ null, termType);
+ if(tree!=null){
+ setSelectedTree(tree);
+ if(dirtyMarkable!=null){
+ dirtyMarkable.forceDirty();
+ }
+ }
}
- }
- });
+ });
+ }
}
- public void setSelectedTree(FeatureTree featureTree, ModifyListener modifyListener) {
+ public void setSelectedTree(TermTree<T> featureTree) {
this.featureTree = featureTree;
-
- getViewer().setInput(featureTree);
-
- Listener[] listeners = getText_title().getListeners(SWT.Modify);
- for (Listener listener : listeners) {
- getText_title().removeListener(SWT.Modify, listener);
- }
- getText_title().setText(featureTree.getTitleCache());
- for (Listener listener : listeners) {
- getText_title().addListener(SWT.Modify, listener);
- }
- getText_title().setEnabled(true);
- text_title.setEnabled(true);
+ viewer.setInput(featureTree);
+ StoreUtil.setTextWithoutModifyListeners(text_title, featureTree!=null?featureTree.getTitleCache():"");
}
- /**
- * @return the featureTree
- */
- public FeatureTree getFeatureTree() {
+ public TermTree<T> 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;
}