899a1128b411ba6cadffd918b0d3276b7e98fc85
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / preference / FeatureMenuPreferences.java
1 /**
2 * Copyright (C) 2007 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.preference;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.eclipse.jface.wizard.WizardDialog;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.MouseAdapter;
17 import org.eclipse.swt.events.MouseEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.ui.IWorkbenchPreferencePage;
22
23 import eu.etaxonomy.cdm.model.description.Feature;
24 import eu.etaxonomy.taxeditor.preference.wizards.FeatureWizard;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26 import eu.etaxonomy.taxeditor.store.StoreUtil;
27
28 /**
29 * @author p.ciardelli
30 * @created 17.09.2008
31 * @version 1.0
32 * @author n.hoffmann
33 */
34 public class FeatureMenuPreferences extends AbstractMenuPreferences implements
35 IWorkbenchPreferencePage {
36
37 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.feature";
38 private Button newButton;
39 private Button editButton;
40 private Button removeButton;
41
42 public FeatureMenuPreferences() {
43 super(CdmStore.getFeatures(), PreferencesUtil.getPreferredFeatures(), "Feature Preferences", "Choose which features you would like to use for descriptive elements.");
44 }
45
46
47 /* (non-Javadoc)
48 * @see org.eclipse.jface.preference.PreferencePage#performOk()
49 */
50 public boolean performOk() {
51 List<Feature> preferredFeatures = new ArrayList<Feature>();
52 for (Object element : getTableViewer().getCheckedElements()){
53 preferredFeatures.add((Feature) element);
54 }
55
56 PreferencesUtil.setPreferredFeatures(preferredFeatures);
57
58 return true;
59 }
60
61 /* (non-Javadoc)
62 * @see eu.etaxonomy.taxeditor.preference.AbstractMenuPreferences#createButtons(org.eclipse.swt.widgets.Composite)
63 */
64 @Override
65 protected void createButtons(Composite buttonContainer) {
66 newButton = new Button(buttonContainer, SWT.PUSH);
67 newButton.setText("New");
68 newButton.setLayoutData(new GridData(SWT.FILL));
69 newButton.addMouseListener(new MouseAdapter(){
70
71 /* (non-Javadoc)
72 * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
73 */
74 @Override
75 public void mouseUp(MouseEvent e) {
76 super.mouseUp(e);
77 FeatureWizard wizard = new FeatureWizard();
78
79 WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
80 dialog.open();
81
82 tableViewer.setInput(CdmStore.getFeatures());
83 }
84
85 });
86
87 editButton = new Button(buttonContainer, SWT.PUSH);
88 editButton.setText("Edit");
89 editButton.setLayoutData(new GridData(SWT.FILL));
90 editButton.addMouseListener(new MouseAdapter(){
91
92 /* (non-Javadoc)
93 * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
94 */
95 @Override
96 public void mouseUp(MouseEvent e) {
97 super.mouseUp(e);
98
99 StoreUtil.notImplementedMessage();
100
101 // editing a feature is somewhat more complicated, because basically one can only edit the representation.
102 // Feature feature = (Feature) ((StructuredSelection) tableViewer.getSelection()).getFirstElement();
103 //
104 // FeatureWizard wizard = new FeatureWizard(feature);
105 //
106 // WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
107 // dialog.open();
108 //
109 // tableViewer.setInput(CdmStore.getFeatures());
110 }
111
112 });
113
114 removeButton = new Button(buttonContainer, SWT.PUSH);
115 removeButton.setText("Remove");
116 removeButton.setLayoutData(new GridData(SWT.FILL));
117 removeButton.addMouseListener(new MouseAdapter(){
118
119 /* (non-Javadoc)
120 * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
121 */
122 @Override
123 public void mouseUp(MouseEvent e) {
124 super.mouseUp(e);
125 StoreUtil.notImplementedMessage();
126 }
127
128 });
129 }
130 }