Project

General

Profile

Revision d8379b7b

IDd8379b7bebfed5afbdfc639071ec9dedb0ec1f2c
Parent 1ba96658
Child 7ec590f2

Added by Patrick Plitzner about 3 years ago

ref #6913 Remove defined term editor

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDragListener.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.definedterm;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.swt.dnd.DragSourceAdapter;
17
import org.eclipse.swt.dnd.DragSourceEvent;
18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20

  
21
/**
22
 * @author l.morris
23
 * @date 10 Jan 2012
24
 *
25
 */
26
public class DefinedTermDragListener extends DragSourceAdapter {
27

  
28
	private Viewer viewer;
29

  
30
	public DefinedTermDragListener(Viewer viewer) {
31
		this.viewer = viewer;
32
	}
33

  
34
	@Override
35
	public void dragStart(DragSourceEvent event) {
36
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
37
	    List list = selection.toList();
38
	    for (Object object : list) {
39
            if(!(object instanceof DefinedTermBase)){
40
                event.doit = false;
41
                return;
42
            }
43
        }
44
		event.doit = true;
45
	}
46

  
47
	@Override
48
	public void dragSetData(DragSourceEvent event) {
49

  
50
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
51
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
52

  
53
		for (Object object : selection.toList()){
54
				definedTerms.add((DefinedTermBase)object);
55
			}
56

  
57
		if (TermTransfer.getInstance().isSupportedType(
58
				event.dataType)) {
59
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
60
		}
61
	}
62

  
63
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDropAdapter.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.definedterm;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13

  
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.jface.viewers.ViewerDropAdapter;
16
import org.eclipse.swt.dnd.DND;
17
import org.eclipse.swt.dnd.DropTargetEvent;
18
import org.eclipse.swt.dnd.TransferData;
19

  
20
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
22
import eu.etaxonomy.cdm.model.common.TermBase;
23
import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
24
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

  
27
/**
28
 * @author l.morris
29
 * @date 10 Jan 2012
30
 *
31
 */
32
public class DefinedTermDropAdapter extends ViewerDropAdapter {
33

  
34
	private final DefinedTermEditor editor;
35
	/**
36
	 * @param viewer
37
	 */
38
	protected DefinedTermDropAdapter(DefinedTermEditor editor) {
39
		super(editor.getViewer());
40
		this.editor = editor;
41
	}
42

  
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
45
	 */
46
	@Override
47
	public boolean performDrop(Object data) {
48

  
49
		TermBase target = (TermBase) getCurrentTarget();//can be vocab
50
		int currentLocation = getCurrentLocation();
51
		//DefinedTermBase[] droppedElements = (DefinedTermBase[]) data;
52
		Object[] droppedTerms = (Object[]) data;
53
		Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
54

  
55
		for (Object droppedTerm : droppedTerms) {
56

  
57
			DefinedTermBase term = (DefinedTermBase) droppedTerm;
58
			sourceTerms.add(term);
59

  
60
		}
61

  
62
		AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions",
63
		        StoreUtil.getUndoContext(),
64
		        target,
65
		        sourceTerms,
66
		        editor,
67
		        currentLocation);
68
		//TODO: implement execute
69
//		StoreUtil.executeOperation(operation);
70
		// select the newly moved objects
71
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms.toArray(new TermBase[sourceTerms.size()])));
72

  
73
		return true;
74
	}
75

  
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
78
	 */
79
	@Override
80
	public boolean validateDrop(Object target, int operation,
81
			TransferData transferType) {
82
		boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);
83
		// maybe don't need this - they will be all TermBase anyway
84
		return target instanceof TermBase && transferDataIsSupported;
85
	}
86

  
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
89
	 */
90
	@Override
91
	public void dragOver(DropTargetEvent event) {
92
	    super.dragOver(event);
93
	    TermBase target = (TermBase) getCurrentTarget();
94
	    if(!(target instanceof OrderedTermBase)) {
95
	        // this is to only disable insert between items
96
	        event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
97
	    }
98

  
99

  
100
	}
101

  
102
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermEditor.java
1
/**
2
 * Copyright (C) 2009 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.editor.definedterm;
10

  
11
import org.eclipse.core.runtime.IProgressMonitor;
12
import org.eclipse.jface.action.GroupMarker;
13
import org.eclipse.jface.action.MenuManager;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.ViewerSorter;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.dnd.DND;
21
import org.eclipse.swt.dnd.Transfer;
22
import org.eclipse.swt.layout.FillLayout;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Menu;
26
import org.eclipse.ui.IEditorInput;
27
import org.eclipse.ui.IEditorSite;
28
import org.eclipse.ui.ISelectionListener;
29
import org.eclipse.ui.ISelectionService;
30
import org.eclipse.ui.IWorkbenchActionConstants;
31
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.PartInitException;
33
import org.eclipse.ui.part.EditorPart;
34

  
35
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
36
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
39
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
40
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
41
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
42
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
43
import eu.etaxonomy.taxeditor.store.CdmStore;
44
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
45

  
46
/**
47
 * @author l.morris
48
 * @date 3 Jan 2012
49
 *
50
 */
51
public class DefinedTermEditor extends EditorPart implements IConversationEnabled, ISelectionListener, IDirtyMarkable, IPostOperationEnabled {
52

  
53
	public static final String ID = "eu.etaxonomy.taxeditor.editor.definedTerm";
54

  
55
	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.store.openDefinedTermEditor";
56

  
57
	protected TreeViewer viewer;
58
	protected ConversationHolder conversation;
59
	private ISelectionService selectionService;
60
	private boolean dirty;
61

  
62

  
63
	private final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
64
	/**
65
	 *
66
	 */
67
	public DefinedTermEditor() {
68
		super();
69
		conversation = CdmStore.createConversation();
70
	}
71

  
72
	@Override
73
	public void createPartControl(Composite parent) {
74

  
75
	//		parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
76

  
77
			FillLayout layout = new FillLayout();
78
			layout.marginHeight = 0;
79
			layout.marginWidth = 0;
80
			layout.type = SWT.VERTICAL;
81

  
82
			parent.setLayout(layout);
83
			viewer = new TreeViewer(parent);
84
			viewer.getControl().setLayoutData(LayoutConstants.FILL());
85
			viewer.setContentProvider(new TermContentProvider());
86
			viewer.setLabelProvider(new TermLabelProvider());
87
			viewer.setSorter(new DefinedTermSorter());
88

  
89
			Transfer[] transfers = new Transfer[] { TermTransfer.getInstance() };
90
			viewer.addDragSupport(dndOperations, transfers, new DefinedTermDragListener(viewer));
91
			viewer.addDropSupport(dndOperations, transfers, new DefinedTermDropAdapter(this));
92

  
93
			getDefinedTermEditorInput().initialiseVocabularies();
94
			viewer.setInput(getDefinedTermEditorInput().getVocabularies());
95

  
96
			getSite().setSelectionProvider(viewer);
97

  
98
			selectionService = getSite().getWorkbenchWindow().getSelectionService();
99
			selectionService.addSelectionListener(this);
100

  
101
			setPartName(getEditorInput().getName());
102
			createMenu();
103
		}
104

  
105

  
106

  
107

  
108
	/**
109
	 *
110
	 */
111
	public TermEditorInput getDefinedTermEditorInput() {
112
		return (TermEditorInput) getEditorInput();
113
	}
114

  
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
117
	 */
118
	@Override
119
	public boolean postOperation(CdmBase objectAffectedByOperation) {
120

  
121

  
122
		viewer.refresh();
123

  
124
		if(objectAffectedByOperation != null){
125
			viewer.setSelection(new StructuredSelection(objectAffectedByOperation));
126
		}
127
		setDirty(true);
128

  
129
		return true;
130
	}
131

  
132
	private void createMenu() {
133
		// register context menu
134
		MenuManager menuManager = new MenuManager();
135
		menuManager
136
				.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
137
		getSite().registerContextMenu(ID, menuManager, viewer);
138

  
139
		Control control = viewer.getControl();
140
		Menu menu = menuManager.createContextMenu(control);
141
		menuManager.setRemoveAllWhenShown(true);
142
		control.setMenu(menu);
143
	}
144

  
145

  
146

  
147

  
148
	@Override
149
	public void doSave(IProgressMonitor monitor) {
150
		getConversationHolder().commit();
151
		getDefinedTermEditorInput().merge();
152
		setDirty(false);
153
		getDefinedTermEditorInput().initialiseVocabularies();
154
		viewer.refresh();
155
	}
156

  
157

  
158
	@Override
159
	public void doSaveAs() {}
160

  
161
	@Override
162
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
163
		setSite(site);
164
		setInput(input);
165

  
166
	}
167

  
168
	@Override
169
	public boolean isDirty() {
170
		return dirty;
171
	}
172

  
173
	@Override
174
	public boolean isSaveAsAllowed() {
175
		return false;
176
	}
177

  
178
	@Override
179
	public void setFocus() {
180
	    viewer.getControl().setFocus();
181
		getConversationHolder().bind();
182
		getDefinedTermEditorInput().bind();
183
	}
184

  
185
	@Override
186
	public void update(CdmDataChangeMap changeEvents) {
187
		// TODO Auto-generated method stub
188

  
189
	}
190

  
191
	@Override
192
	public ConversationHolder getConversationHolder() {
193
		return conversation;
194
	}
195

  
196
	@Override
197
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
198
		// TODO Auto-generated method stub
199

  
200
	}
201

  
202
	@Override
203
	public void changed(Object element) {
204
		dirty = true;
205
		setDirty(true);
206
		viewer.update(element, null);
207
	}
208

  
209
	/* (non-Javadoc)
210
	 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
211
	 */
212
	@Override
213
	public void forceDirty() {
214
	    changed(null);
215
	}
216

  
217
	/**
218
	 * @param dirty the dirty to set
219
	 */
220
	public void setDirty(boolean dirty) {
221
		this.dirty = dirty;
222
		firePropertyChange(PROP_DIRTY);
223
	}
224

  
225
	@Override
226
	public boolean onComplete() {
227
		// TODO Auto-generated method stub
228
		return false;
229
	}
230

  
231
	/**
232
	 *
233
	 */
234
	public TreeViewer getViewer() {
235
		return viewer;
236
	}
237

  
238
	private class DefinedTermSorter extends ViewerSorter {
239

  
240
	    @Override
241
	    public int compare(Viewer viewer, Object e1, Object e2) {
242
	        // the comparison value in this method determines the
243
	        // location <-> add term method used in the MoveDefinedTermOperation
244
	        // execute call
245
	        if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {
246
	            OrderedTermBase otbe1 = (OrderedTermBase)e1;
247
	            OrderedTermBase otbe2 = (OrderedTermBase)e2;
248
	            if(otbe1.getOrderIndex() == otbe2.getOrderIndex()) {
249
	                return 0;
250
	            } else if (otbe1.getOrderIndex() < otbe2.getOrderIndex()){
251
	            	return -1;
252
	            } else{
253
	            	return 1;
254
	            }
255
	        } else {
256
	            return super.compare(viewer, e1, e2);
257
	        }
258
	    }
259
	}
260

  
261
	@Override
262
	public void dispose() {
263
	    getDefinedTermEditorInput().dispose();
264
	    super.dispose();
265
	}
266
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.editor.definedterm;
11

  
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.Collections;
15
import java.util.Comparator;
16
import java.util.EnumSet;
17
import java.util.HashMap;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.Set;
21

  
22
import org.eclipse.jface.action.IContributionItem;
23
import org.eclipse.jface.action.MenuManager;
24
import org.eclipse.jface.action.Separator;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.actions.CompoundContributionItem;
28
import org.eclipse.ui.menus.CommandContributionItem;
29
import org.eclipse.ui.menus.CommandContributionItemParameter;
30

  
31
import eu.etaxonomy.cdm.model.common.TermType;
32
import eu.etaxonomy.taxeditor.l10n.Messages;
33
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34
import eu.etaxonomy.taxeditor.store.CdmStore;
35

  
36
/**
37
 * Menu used in the store plugin xml to dynamically generate menu (sub-menu) contribution items
38
 * for term types which when clicked open the defined term editor for the chosen term type
39
 *
40
 * @author pplitzner
41
 * @date 21 Jul 2015
42
 *
43
 */
44

  
45
public class DefinedTermMenu extends CompoundContributionItem {
46

  
47

  
48
    @Override
49
    protected IContributionItem[] getContributionItems() {
50
        Collection<IContributionItem> items = new ArrayList<IContributionItem>();
51
        if(CdmStore.isActive()){
52
            MenuManager dtMenuManager =
53
                    new MenuManager(Messages.DefinedTermMenu_TERM_EDITOR,"eu.etaxonomy.taxeditor.store.definedTermEditorMenu"); //$NON-NLS-2$
54

  
55
            dtMenuManager.setVisible(true);
56

  
57
            items.add(dtMenuManager);
58
            //add Feature and NamedArea to top level
59
            dtMenuManager.add(addChildTermsToMenuManager(TermType.Feature));
60
            dtMenuManager.add(addChildTermsToMenuManager(TermType.NamedArea));
61
            dtMenuManager.add(new Separator());
62

  
63
            MenuManager otherMenuManager =
64
                    new MenuManager(Messages.DefinedTermMenu_OTHERS,"eu.etaxonomy.taxeditor.store.term.other.menu"); //$NON-NLS-2$
65
            otherMenuManager.setVisible(true);
66
            dtMenuManager.add(otherMenuManager);
67
            dtMenuManager.add(new Separator());
68
            dtMenuManager.add(createFeatureTreeMenuItem());
69

  
70
            List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class));
71
            Collections.sort(ttList,new SortByTermTypeMessage());
72
            for (TermType tt : ttList)
73
            {
74
                //skip Feature and NamedArea as they have already been added to top level
75
                if(tt.equals(TermType.Feature) || tt.equals(TermType.NamedArea)){
76
                    continue;
77
                }
78
                // if term type has a parent, do not add it
79
                // it will be added in the recursive call
80
                if(tt.getKindOf() == null) {
81
                    IContributionItem ici = addChildTermsToMenuManager(tt);
82
                    if(ici != null) {
83
                        otherMenuManager.add(ici);
84
                    }
85
                }
86
            }
87
        }
88
	    return items.toArray(new IContributionItem[]{});
89
	}
90

  
91
	private IContributionItem addChildTermsToMenuManager(TermType termType) {
92

  
93
		//FIXME : need a better way to find out if a term type can be editable (ticket 3853)
94
		if(termType.getEmptyDefinedTermBase() != null) {
95
			Set<TermType> children = termType.getGeneralizationOf();
96
			// term type has no children, so create menu item
97
			if(children.isEmpty()) {
98
				return createMenuItem(termType);
99
			}
100
			// term type has children, so create sub menu
101
			MenuManager dtMenuManager =
102
					new MenuManager(termType.getMessage(PreferencesUtil.getGlobalLanguage()),"eu.etaxonomy.taxeditor.store." + termType.getKey() + Messages.DefinedTermMenu_MENU); //$NON-NLS-1$
103
			dtMenuManager.setVisible(true);
104
			dtMenuManager.add(createDefaultMenuItem(termType));
105

  
106
			Separator sep = new Separator();
107
			dtMenuManager.add(sep);
108
			// add child items to the sub menu
109
			for(TermType tt : children) {
110
				IContributionItem item = addChildTermsToMenuManager(tt);
111
				if(item != null) {
112
					dtMenuManager.add(item);
113
				}
114
			}
115
			return dtMenuManager;
116
		} else {
117
			return null;
118
		}
119

  
120
	}
121

  
122
	private CommandContributionItem createMenuItem(TermType termType) {
123

  
124
		Map<String, String> params = new HashMap<String, String>();
125
		params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", //$NON-NLS-1$
126
				termType.getUuid().toString());
127

  
128
        CommandContributionItemParameter p = new CommandContributionItemParameter(
129
                PlatformUI.getWorkbench(),
130
                "", //$NON-NLS-1$
131
                "eu.etaxonomy.taxeditor.store.openDefinedTermEditor", //$NON-NLS-1$
132
                params,
133
                null,
134
                null,
135
                null,
136
                termType.getMessage(),
137
                "", //$NON-NLS-1$
138
                "", //$NON-NLS-1$
139
                SWT.PUSH,
140
                "", //$NON-NLS-1$
141
                true);
142

  
143
        CommandContributionItem item = new CommandContributionItem(p);
144
        return item;
145

  
146
	}
147

  
148
	private CommandContributionItem createFeatureTreeMenuItem() {
149

  
150
		Map<String, String> params = new HashMap<String, String>();
151
		params.put("eu.etaxonomy.taxeditor.workbench.commandparameter.partName", //$NON-NLS-1$
152
				"eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor"); //$NON-NLS-1$
153

  
154
        CommandContributionItemParameter p = new CommandContributionItemParameter(
155
                PlatformUI.getWorkbench(),
156
                "eu.etaxonomy.taxeditor.featuretree.commandContributionItemParameter", //$NON-NLS-1$
157
                "eu.etaxonomy.taxeditor.command.openPart", //$NON-NLS-1$
158
                params,
159
                null,
160
                null,
161
                null,
162
                Messages.DefinedTermMenu_FEATURE_TREE,
163
                "", //$NON-NLS-1$
164
                "", //$NON-NLS-1$
165
                SWT.PUSH,
166
                "", //$NON-NLS-1$
167
                true);
168

  
169

  
170

  
171
        CommandContributionItem item = new CommandContributionItem(p);
172
        return item;
173

  
174
	}
175

  
176
	private CommandContributionItem createDefaultMenuItem(TermType termType) {
177

  
178
	    Map<String, String> params = new HashMap<String, String>();
179
	    params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", //$NON-NLS-1$
180
	            termType.getUuid().toString());
181

  
182
	    CommandContributionItemParameter p = new CommandContributionItemParameter(
183
	            PlatformUI.getWorkbench(),
184
	            "", //$NON-NLS-1$
185
	            "eu.etaxonomy.taxeditor.store.openDefinedTermEditor", //$NON-NLS-1$
186
	            params,
187
	            null,
188
	            null,
189
	            null,
190
	            String.format(Messages.DefinedTermMenu_OTHER_S, termType.getMessage()),
191
	            "", //$NON-NLS-1$
192
	            "", //$NON-NLS-1$
193
	            SWT.PUSH,
194
	            "", //$NON-NLS-1$
195
	            true);
196

  
197

  
198

  
199
	    CommandContributionItem item = new CommandContributionItem(p);
200
	    return item;
201

  
202
	}
203

  
204
	private class SortByTermTypeMessage implements Comparator<TermType> {
205
	    @Override
206
        public int compare(TermType t1, TermType t2) {
207
	        if (t1.equals(t2)){
208
	            return 0;
209
	        }
210
	        int result = t1.getMessage().compareTo(t2.getMessage());
211
	        if (result == 0){
212
	            return t1.compareTo(t2);
213
	        }
214
	        return result;
215
	    }
216
	}
217

  
218

  
219
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateDefinedTermHandler.java
1
/**
2
 * Copyright (C) 2009 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
10

  
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.common.NotDefinedException;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

  
19
import eu.etaxonomy.cdm.model.common.TermBase;
20
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
21
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

  
27
/**
28
 * @author l.morris
29
 * @date 21 Dec 2011
30
 *
31
 */
32
public class CreateDefinedTermHandler extends AbstractHandler {
33

  
34
	@Override
35
	public Object execute(ExecutionEvent event) throws ExecutionException {
36
	    boolean addTermAsKindOf =
37
	            event.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
38

  
39
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
40
				.getActiveEditor(event);
41

  
42
		if (editor instanceof DefinedTermEditor){
43
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
44
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
45
					.getCurrentSelection(event);
46
			if (selection.getFirstElement() instanceof TermBase) {
47
				try {
48
					String label = event.getCommand().getName();
49
					IUndoContext undoContext = StoreUtil.getUndoContext();
50

  
51
					TermBase termBase = (TermBase) selection.getFirstElement();
52

  
53
					AbstractPostOperation operation =
54
							new CreateDefinedTermOperation(label,
55
									undoContext,
56
									termBase,
57
									dfe.getDefinedTermEditorInput(),
58
									editor, addTermAsKindOf);
59

  
60
				} catch (NotDefinedException e) {
61
					MessagingUtils.error(getClass(), e);
62
				}
63
			}
64
		}
65

  
66
		return null;
67
	}
68

  
69
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateTermVocabularyHandler.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
10

  
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.core.commands.common.NotDefinedException;
16
import org.eclipse.core.commands.operations.IUndoContext;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

  
19
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
20
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateTermVocabularyOperation;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25

  
26
/**
27
 * @author l.morris
28
 * @date 21 Dec 2011
29
 *
30
 */
31
public class CreateTermVocabularyHandler extends AbstractHandler implements
32
		IHandler {
33

  
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36
	 */
37
	@Override
38
	public Object execute(ExecutionEvent event) throws ExecutionException {
39
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
40
				.getActiveEditor(event);
41

  
42
		if (editor instanceof DefinedTermEditor){
43
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
44

  
45
			try {
46
				String label = event.getCommand().getName();
47
				IUndoContext undoContext = StoreUtil.getUndoContext();
48

  
49
				AbstractPostOperation operation =
50
						new CreateTermVocabularyOperation(label,
51
								undoContext,
52
								dfe.getDefinedTermEditorInput(),
53
								editor);
54

  
55
			} catch (NotDefinedException e) {
56
				MessagingUtils.error(getClass(), e);
57
			}
58
		}
59
		return null;
60
	}
61
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/DeleteTermBaseHandler.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
10

  
11
import java.util.Iterator;
12

  
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.handlers.HandlerUtil;
23

  
24
import eu.etaxonomy.cdm.model.common.TermBase;
25
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
26
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
30

  
31
/**
32
 * @author l.morris
33
 * @date 22 Dec 2011
34
 *
35
 */
36
public class DeleteTermBaseHandler extends AbstractHandler {
37

  
38
	@Override
39
	public Object execute(ExecutionEvent event) throws ExecutionException {
40
		IEditorPart editor = HandlerUtil
41
				.getActiveEditor(event);
42

  
43
		if (editor.isDirty()){
44
			boolean proceed = MessageDialog.openQuestion(null,
45
					"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
46
			if (proceed) {
47
				editor.doSave(null);
48
			} else {
49
				return null;
50
			}
51
		}
52
		if (editor instanceof DefinedTermEditor){
53
		    DefinedTermEditor dfe = (DefinedTermEditor) editor;
54
		    try {
55
		        String label = event.getCommand().getName();
56
		        IUndoContext undoContext = StoreUtil.getUndoContext();
57

  
58
		        ISelection selection = dfe.getViewer().getSelection();
59
		        if(selection instanceof IStructuredSelection){
60

  
61
		            Iterator<TermBase> selectionIterator = ((IStructuredSelection) selection).iterator();
62

  
63
		            while (selectionIterator.hasNext()){
64

  
65
		                TermBase term = selectionIterator.next();
66

  
67

  
68
		                AbstractPostOperation operation =
69
		                        new DeleteTermBaseOperation(label,
70
		                                undoContext,
71
		                                term,
72
		                                dfe.getDefinedTermEditorInput(),
73
		                                dfe);
74
		            }
75
		        }
76
		    } catch (NotDefinedException e) {
77
		        MessagingUtils.error(getClass(), e);
78
		    }
79
		}
80
		return null;
81
	}
82

  
83
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/OpenDefinedTermEditorHandler.java
1
/**
2
 * Copyright (C) 2009 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

  
10
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.IHandler;
15

  
16

  
17
/**
18
 * @author l.morris
19
 * @date 8 Dec 2011
20
 *
21
 */
22
public class OpenDefinedTermEditorHandler extends AbstractHandler implements IHandler {
23

  
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
26
	 */
27
	@Override
28
	public Object execute(ExecutionEvent event) throws ExecutionException {
29

  
30
//		String termTypeUuid = event.getParameter("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid");
31
//		IWorkbenchPage activePage = StoreUtil.getActivePage();
32
//		try {
33
//			activePage.openEditor(new TermEditorInput(TermType.getByUuid(UUID.fromString(termTypeUuid))), DefinedTermEditor.ID);
34
//		} catch (PartInitException e) {
35
//
36
//			String PID = "eu.etaxonomy.taxeditor.application";
37
//			MultiStatus info = new MultiStatus(PID, 1, "You might be missing sufficient permissions to open the Defined Term Editor", null);
38
//			info.add(new Status(IStatus.WARNING, PID, 1, e.getMessage(), null));
39
//			MessagingUtils.warningDialog("Cannot open Defined Term Editor", getClass(), info);
40
//		}
41

  
42
		return null;
43
	}
44

  
45
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)