adapt comparators to new model.compare structure (cont.)
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / handler / CreateDescriptiveDataSetHandler.java
1
2 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler;
3
4 import javax.inject.Named;
5
6 import org.eclipse.e4.core.di.annotations.CanExecute;
7 import org.eclipse.e4.core.di.annotations.Execute;
8 import org.eclipse.e4.ui.model.application.MApplication;
9 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
10 import org.eclipse.e4.ui.services.IServiceConstants;
11 import org.eclipse.e4.ui.workbench.modeling.EModelService;
12 import org.eclipse.e4.ui.workbench.modeling.EPartService;
13 import org.eclipse.jface.dialogs.InputDialog;
14 import org.eclipse.jface.window.Window;
15 import org.eclipse.swt.widgets.Shell;
16
17 import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
18 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
19 import eu.etaxonomy.taxeditor.editor.EditorUtil;
20 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator;
21 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 public class CreateDescriptiveDataSetHandler {
25
26 @Execute
27 public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
28 @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
29 EModelService modelService, EPartService partService, MApplication application) {
30 DescriptiveDataSetNavigator navigator = (DescriptiveDataSetNavigator) activePart.getObject();
31 InputDialog dialog = new InputDialog(shell,Messages.CreateDescriptiveDataSetHandler_NEW_DATA_SET_DIALOG_TITLE, null,
32 Messages.CreateDescriptiveDataSetHandler_NEW_DESCRIPTIVE_DATA_SET, null);
33 if (dialog.open() == Window.OK) {
34 String dataSetName = dialog.getValue();
35 DescriptiveDataSet descriptiveDataSet = DescriptiveDataSet.NewInstance();
36 descriptiveDataSet.setLabel(dataSetName);
37 CdmStore.getService(IDescriptiveDataSetService.class).merge(descriptiveDataSet, true);
38 navigator.getConversationHolder().commit();
39 navigator.addDescriptiveDataSet(descriptiveDataSet);
40 EditorUtil.openDescriptiveDataSetEditor(descriptiveDataSet.getUuid(), modelService, partService, application);
41 }
42 }
43
44 @CanExecute
45 public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
46 return activePart.getObject() instanceof DescriptiveDataSetNavigator;
47 }
48 }