*/
package eu.etaxonomy.taxeditor.featuretree.e4;
+import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DragSourceListener;
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
*/
public class FeatureTreeEditorComposite extends Composite{
+ private FeatureTree featureTree;
+
private Label label_title;
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);
label_title = new Label(composite_treeTitle, SWT.NULL);
label_title.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- label_title.setText("Feature Tree");
+ label_title.setText(Messages.FeatureTreeEditorComposite_FEATURE_TREE);
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);
- 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("Open Tree");
+ 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("Add a feature to this feature tree.");
- 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("Remove a feature from this feature tree.");
- 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, 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 selectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
viewer.setContentProvider(new FeatureTreeContentProvider());
viewer.setLabelProvider(new FeatureTreeLabelProvider());
int ops = DND.DROP_COPY | DND.DROP_MOVE;
- Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
- .getInstance() };
- viewer.addDragSupport(ops, transfers, dragSourceListener);
- viewer.addDropSupport(ops, transfers, dropTargetListener);
-
- viewer.addSelectionChangedListener(viewerSelectionChangedListener);
-
- button_add.addSelectionListener(addButtonSelectionListener);
- button_remove.addSelectionListener(removeButtonSelectionListener);
+ Transfer[] transfers = new Transfer[] {
+ FeatureNodeTransfer.getInstance(),
+ TermTransfer.getInstance(),
+ LocalSelectionTransfer.getTransfer()
+ };
+ if(dragSourceListener!=null){
+ viewer.addDragSupport(ops, transfers, dragSourceListener);
+ }
+ if(dropTargetListener!=null){
+ viewer.addDropSupport(ops, transfers, dropTargetListener);
+ }
+
+ if(viewerSelectionChangedListener!=null){
+ viewer.addSelectionChangedListener(viewerSelectionChangedListener);
+ }
+
+ if(textModifyListener!=null){
+ text_title.addModifyListener(textModifyListener);
+ }
+
+ //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();
+ }
+ }
+ }
+ });
+ }
+ }
- btnOpenFeatureTree.addSelectionListener(selectionListener);
+ public void setSelectedTree(FeatureTree featureTree) {
+ this.featureTree = featureTree;
+
+ viewer.setInput(featureTree);
+
+ 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);
}
- /**
- * @return the label_title
- */
- public Label getLabel_title() {
- return label_title;
+ public FeatureTree getFeatureTree() {
+ return featureTree;
}
- /**
- * @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 getButton_add() {
- return button_add;
- }
-
- /**
- * @return the button_remove
- */
- public Button getButton_remove() {
- return button_remove;
- }
-
}