Project

General

Profile

Revision 804fe7cc

ID804fe7cc242d3e25e2634d0ee66946cd790d0078
Parent 853ff11f
Child 3ca6cafb

Added by Patrick Plitzner over 3 years ago

ref #6806 remove buttons from FeatureTreeEditorComposite

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterEditor.java
157 157
    private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
158 158
        FeatureTreeEditorComposite featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.BORDER);
159 159
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
160
        featureTreeEditorComposite.getComposite_buttons().setVisible(false);
161 160
        return featureTreeEditorComposite;
162 161
    }
163 162

  
164 163
    private void initFeatureTreeComposite(FeatureTreeEditorComposite featureTreeEditorComposite,
165 164
            FeatureNodeDragListener featureNodeDragListener, FeatureNodeDropAdapter featureNodeDropAdapter) {
166 165
        featureTreeEditorComposite.init(featureNodeDragListener, featureNodeDropAdapter, this,
167
                new FeatureTreeChooserListener(featureTreeEditorComposite), new SelectionAdapter() {
168
                }, new SelectionAdapter() {
169
                }, new SelectionAdapter() {
170
                });
166
                new FeatureTreeChooserListener(featureTreeEditorComposite));
171 167
    }
172 168

  
173 169
    @Focus
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
11 11

  
12 12
import java.util.ArrayList;
13 13
import java.util.Arrays;
14
import java.util.Collection;
15 14
import java.util.HashMap;
16 15
import java.util.List;
17 16
import java.util.Map;
......
20 19
import javax.annotation.PreDestroy;
21 20
import javax.inject.Inject;
22 21

  
23
import org.eclipse.core.runtime.IStatus;
24 22
import org.eclipse.e4.ui.di.Focus;
25 23
import org.eclipse.e4.ui.di.Persist;
26 24
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
27 25
import org.eclipse.e4.ui.services.EMenuService;
28 26
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
29 27
import org.eclipse.jface.viewers.ISelectionChangedListener;
30
import org.eclipse.jface.viewers.IStructuredSelection;
31 28
import org.eclipse.jface.viewers.SelectionChangedEvent;
32 29
import org.eclipse.jface.viewers.TreeViewer;
33
import org.eclipse.jface.wizard.WizardDialog;
34 30
import org.eclipse.swt.SWT;
35 31
import org.eclipse.swt.events.ModifyEvent;
36 32
import org.eclipse.swt.events.ModifyListener;
......
39 35
import org.eclipse.swt.widgets.Composite;
40 36

  
41 37
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
42
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
43 38
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
44
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
45
import eu.etaxonomy.cdm.model.description.Feature;
46 39
import eu.etaxonomy.cdm.model.description.FeatureNode;
47 40
import eu.etaxonomy.cdm.model.description.FeatureTree;
48
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
49 41
import eu.etaxonomy.taxeditor.model.AbstractUtility;
50 42
import eu.etaxonomy.taxeditor.model.MessagingUtils;
51 43
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
......
111 103
                            composite.setSelectedTree(tree, FeatureTreeEditor.this);
112 104
                        }
113 105
                    }
114
                }, new AddButtonListener(), new RemoveSelectionListener(), new FeatureTreeExportListener(composite.getDisplay().getActiveShell(), composite));
106
                });
115 107

  
116 108
        //create context menu
117 109
        menuService.registerContextMenu(composite.getViewer().getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor");
......
139 131
	/** {@inheritDoc} */
140 132
	@Override
141 133
	public void selectionChanged(SelectionChangedEvent event) {
142
		IStructuredSelection selection = (IStructuredSelection) event
143
				.getSelection();
144

  
145
		composite.getBtnAdd().setEnabled(selection.size() <= 1);
146
		composite.getBtnRemove().setEnabled(selection.size() > 0);
147 134
		//propagate selection
148 135
		selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event));
149 136
	}
......
221 208
        return root;
222 209
    }
223 210

  
224
	private class AddButtonListener extends SelectionAdapter {
225
		@Override
226
		public void widgetSelected(SelectionEvent e) {
227
			AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
228
			WizardDialog dialog = new WizardDialog(e.widget.getDisplay().getActiveShell(), wizard);
229

  
230
			if (dialog.open() == IStatus.OK) {
231
                FeatureNode parent = ((FeatureTree) composite.getViewer().getInput()).getRoot();
232
                Collection<Feature> additionalFeatures = wizard.getAdditionalFeatures();
233
                for (Feature feature : additionalFeatures) {
234
                    if(!getSelectedFeatureTree().getDistinctFeatures().contains(feature)){
235
                        CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(parent.getUuid(), feature.getUuid());
236
                    }
237
				}
238
				setDirty(true);
239
				composite.getViewer().refresh();
240
				composite.getViewer().expandToLevel(parent, 1);
241
			}
242
		}
243

  
244
	}
245

  
246
	private class RemoveSelectionListener extends SelectionAdapter {
247
		@Override
248
		public void widgetSelected(SelectionEvent e) {
249
			IStructuredSelection selection = (IStructuredSelection) composite.getViewer()
250
					.getSelection();
251

  
252
			for (Object selectedObject : selection.toArray()) {
253
				FeatureNode featureNode = (FeatureNode) selectedObject;
254
				CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator());
255

  
256
			}
257
			setDirty(true);
258
			composite.getViewer().refresh();
259
		}
260
	}
261

  
262 211
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
32 32
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
33 33
import eu.etaxonomy.taxeditor.l10n.Messages;
34 34
import eu.etaxonomy.taxeditor.model.ImageResources;
35
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
36
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
37 35

  
38 36
/**
39 37
 * @author pplitzner
......
48 46
    private Text text_title;
49 47
    private Button btnOpenFeatureTree;
50 48
    private TreeViewer viewer;
51
    private Button btnAdd;
52
    private Button btnRemove;
53
    private Button btnExportTree;
54

  
55
    private Composite composite_buttons;
56 49

  
57 50
    public FeatureTreeEditorComposite(Composite parent, int style) {
58 51
        super(parent, style);
59
        setLayout(new GridLayout(2, false));
52
        setLayout(new GridLayout(1, false));
60 53

  
61 54
        Composite composite_treeTitle = new Composite(this, SWT.NULL);
62 55
        composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
63 56
                false));
64
        GridLayout gl_composite_treeTitle = new GridLayout(2, false);
57
        GridLayout gl_composite_treeTitle = new GridLayout(3, false);
65 58
        gl_composite_treeTitle.marginWidth = 0;
66 59
        composite_treeTitle.setLayout(gl_composite_treeTitle);
67 60

  
......
73 66
        text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
74 67
        text_title.setEnabled(false);
75 68

  
76
        btnOpenFeatureTree = new Button(this, SWT.NONE);
69
        btnOpenFeatureTree = new Button(composite_treeTitle, SWT.NONE);
77 70
        btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
78 71
        btnOpenFeatureTree.setToolTipText(Messages.FeatureTreeEditorComposite_OPEN_TREE);
79 72
        btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
80 73

  
81 74
        viewer = new TreeViewer(this);
82 75
        Tree tree = viewer.getTree();
83
        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
76
        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
84 77
        viewer.getControl().setLayoutData(
85 78
                new GridData(SWT.FILL, SWT.FILL, true, true));
86

  
87
        composite_buttons = new Composite(this,
88
                SWT.NULL);
89
        composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
90
                false));
91
        composite_buttons.setLayout(new GridLayout());
92

  
93
        btnAdd = new Button(composite_buttons, SWT.PUSH);
94
        btnAdd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
95
        btnAdd.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
96
        btnAdd.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
97
        btnRemove = new Button(composite_buttons, SWT.PUSH);
98
        btnRemove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
99
        btnRemove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
100
        btnRemove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
101

  
102
        btnExportTree = new Button(composite_buttons, SWT.NONE);
103
        btnExportTree.setToolTipText("Export feature tree");
104
        btnExportTree.setImage(ImageResources.getImage(ImageResources.MOVE_ICON));
105
        btnExportTree.setVisible(TaxeditorStorePlugin.getDefault().getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES));
106

  
107
        setButtonsEnabled(false);
108 79
    }
109 80

  
110
    public void init(DragSourceListener dragSourceListener,
111
            DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
112
            SelectionListener openFeatureTreeSelectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener, SelectionListener exportButtonSelectionListener) {
81
    public void init(DragSourceListener dragSourceListener, DropTargetListener dropTargetListener,
82
            ISelectionChangedListener viewerSelectionChangedListener,
83
            SelectionListener openFeatureTreeSelectionListener) {
113 84
        viewer.setContentProvider(new FeatureTreeContentProvider());
114 85
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
115 86

  
......
125 96

  
126 97
        viewer.addSelectionChangedListener(viewerSelectionChangedListener);
127 98

  
128
        btnAdd.addSelectionListener(addButtonSelectionListener);
129
        btnRemove.addSelectionListener(removeButtonSelectionListener);
130
        btnExportTree.addSelectionListener(exportButtonSelectionListener);
131

  
132 99
        btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
133 100
    }
134 101

  
......
141 108
        getText_title().setText(featureTree.getTitleCache());
142 109
        getText_title().addModifyListener(modifyListener);
143 110
        getText_title().setEnabled(true);
144
        setButtonsEnabled(true);
145 111
        text_title.setEnabled(true);
146 112
    }
147 113

  
148
    private void setButtonsEnabled(boolean enabled){
149
        btnAdd.setEnabled(enabled);
150
        btnRemove.setEnabled(enabled);
151
        btnExportTree.setEnabled(enabled);
152
    }
153

  
154 114
    /**
155 115
     * @return the featureTree
156 116
     */
......
186 146
        return viewer;
187 147
    }
188 148

  
189
    /**
190
     * @return the button_add
191
     */
192
    public Button getBtnAdd() {
193
        return btnAdd;
194
    }
195

  
196
    /**
197
     * @return the button_remove
198
     */
199
    public Button getBtnRemove() {
200
        return btnRemove;
201
    }
202

  
203
    /**
204
     * @return the composite_buttons
205
     */
206
    public Composite getComposite_buttons() {
207
        return composite_buttons;
208
    }
209

  
210
    /**
211
     * @return the btnExportTree
212
     */
213
    public Button getBtnExportTree() {
214
        return btnExportTree;
215
    }
216

  
217 149
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)