Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/SetMarkerContributionItems.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.bulkeditor.command; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.eclipse.jface.action.ContributionItem; |
|
18 |
import org.eclipse.jface.action.IContributionItem; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.SelectionAdapter; |
|
21 |
import org.eclipse.swt.events.SelectionEvent; |
|
22 |
import org.eclipse.swt.widgets.Event; |
|
23 |
import org.eclipse.swt.widgets.Menu; |
|
24 |
import org.eclipse.swt.widgets.MenuItem; |
|
25 |
import org.eclipse.ui.IEditorPart; |
|
26 |
import org.eclipse.ui.PlatformUI; |
|
27 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
28 |
import org.eclipse.ui.handlers.IHandlerService; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
31 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
32 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
33 |
import eu.etaxonomy.taxeditor.store.TermStore; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author p.ciardelli |
|
37 |
* @created 20.10.2009 |
|
38 |
* @version 1.0 |
|
39 |
*/ |
|
40 |
public class SetMarkerContributionItems extends CompoundContributionItem { |
|
41 |
private static final Logger logger = Logger |
|
42 |
.getLogger(SetMarkerContributionItems.class); |
|
43 |
|
|
44 |
/* (non-Javadoc) |
|
45 |
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() |
|
46 |
*/ |
|
47 |
@Override |
|
48 |
protected IContributionItem[] getContributionItems() { |
|
49 |
|
|
50 |
List<IContributionItem> contributions = new ArrayList<IContributionItem>(); |
|
51 |
|
|
52 |
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); |
|
53 |
if (editor.getEditorInput() instanceof AbstractBulkEditorInput) { |
|
54 |
AbstractBulkEditorInput input = (AbstractBulkEditorInput) editor.getEditorInput(); |
|
55 |
for (final MarkerType markerType : TermStore.getNonTechnicalMarkerTypes()) { |
|
56 |
if (input.isMarkerTypeEditingEnabled(markerType) && PreferencesUtil.getEditMarkerTypePreference(input, markerType)) { |
|
57 |
contributions.add(new ContributionItem() { |
|
58 |
/* (non-Javadoc) |
|
59 |
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int) |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public void fill(Menu menu, int index) { |
|
63 |
MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE, index); |
|
64 |
subMenuItem.setText("Set Flag - \"" + markerType.getLabel() + "\""); |
|
65 |
Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN); |
|
66 |
subMenuItem.setMenu(subMenu); |
|
67 |
|
|
68 |
MenuItem trueItem = new MenuItem(subMenu, SWT.PUSH); |
|
69 |
trueItem.setText("true"); |
|
70 |
trueItem.addSelectionListener(new SelectionAdapter() { |
|
71 |
public void widgetSelected(SelectionEvent e) { |
|
72 |
doSetFlagCommand(markerType, true); |
|
73 |
} |
|
74 |
}); |
|
75 |
|
|
76 |
MenuItem falseItem = new MenuItem(subMenu, SWT.PUSH); |
|
77 |
falseItem.setText("false"); |
|
78 |
falseItem.addSelectionListener(new SelectionAdapter() { |
|
79 |
public void widgetSelected(SelectionEvent e) { |
|
80 |
doSetFlagCommand(markerType, false); |
|
81 |
} |
|
82 |
}); |
|
83 |
} |
|
84 |
}); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
return (IContributionItem[]) contributions.toArray(new IContributionItem[contributions.size()]); |
|
89 |
} |
|
90 |
|
|
91 |
private void doSetFlagCommand(MarkerType markerType, boolean flag) { |
|
92 |
try { |
|
93 |
IHandlerService handlerService = |
|
94 |
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); |
|
95 |
Event event = new Event(); |
|
96 |
event.data = markerType; |
|
97 |
if (flag) { |
|
98 |
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagTrue", event); |
|
99 |
} else { |
|
100 |
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagFalse", event); |
|
101 |
} |
|
102 |
} catch (Exception e) { |
|
103 |
// TODO Auto-generated catch block |
|
104 |
e.printStackTrace(); |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.bulkeditor.command; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.eclipse.jface.action.ContributionItem; |
|
18 |
import org.eclipse.jface.action.IContributionItem; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.SelectionAdapter; |
|
21 |
import org.eclipse.swt.events.SelectionEvent; |
|
22 |
import org.eclipse.swt.widgets.Event; |
|
23 |
import org.eclipse.swt.widgets.Menu; |
|
24 |
import org.eclipse.swt.widgets.MenuItem; |
|
25 |
import org.eclipse.ui.IEditorPart; |
|
26 |
import org.eclipse.ui.PlatformUI; |
|
27 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
28 |
import org.eclipse.ui.handlers.IHandlerService; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
31 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
32 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
33 |
import eu.etaxonomy.taxeditor.store.TermStore; |
|
34 |
|
|
35 |
/** |
|
36 |
* <p>SetMarkerContributionItems class.</p> |
|
37 |
* |
|
38 |
* @author p.ciardelli |
|
39 |
* @created 20.10.2009 |
|
40 |
* @version 1.0 |
|
41 |
*/ |
|
42 |
public class SetMarkerContributionItems extends CompoundContributionItem { |
|
43 |
private static final Logger logger = Logger |
|
44 |
.getLogger(SetMarkerContributionItems.class); |
|
45 |
|
|
46 |
/* (non-Javadoc) |
|
47 |
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() |
|
48 |
*/ |
|
49 |
/** {@inheritDoc} */ |
|
50 |
@Override |
|
51 |
protected IContributionItem[] getContributionItems() { |
|
52 |
|
|
53 |
List<IContributionItem> contributions = new ArrayList<IContributionItem>(); |
|
54 |
|
|
55 |
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); |
|
56 |
if (editor.getEditorInput() instanceof AbstractBulkEditorInput) { |
|
57 |
AbstractBulkEditorInput input = (AbstractBulkEditorInput) editor.getEditorInput(); |
|
58 |
for (final MarkerType markerType : TermStore.getNonTechnicalMarkerTypes()) { |
|
59 |
if (input.isMarkerTypeEditingEnabled(markerType) && PreferencesUtil.getEditMarkerTypePreference(input, markerType)) { |
|
60 |
contributions.add(new ContributionItem() { |
|
61 |
/* (non-Javadoc) |
|
62 |
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int) |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public void fill(Menu menu, int index) { |
|
66 |
MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE, index); |
|
67 |
subMenuItem.setText("Set Flag - \"" + markerType.getLabel() + "\""); |
|
68 |
Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN); |
|
69 |
subMenuItem.setMenu(subMenu); |
|
70 |
|
|
71 |
MenuItem trueItem = new MenuItem(subMenu, SWT.PUSH); |
|
72 |
trueItem.setText("true"); |
|
73 |
trueItem.addSelectionListener(new SelectionAdapter() { |
|
74 |
public void widgetSelected(SelectionEvent e) { |
|
75 |
doSetFlagCommand(markerType, true); |
|
76 |
} |
|
77 |
}); |
|
78 |
|
|
79 |
MenuItem falseItem = new MenuItem(subMenu, SWT.PUSH); |
|
80 |
falseItem.setText("false"); |
|
81 |
falseItem.addSelectionListener(new SelectionAdapter() { |
|
82 |
public void widgetSelected(SelectionEvent e) { |
|
83 |
doSetFlagCommand(markerType, false); |
|
84 |
} |
|
85 |
}); |
|
86 |
} |
|
87 |
}); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
return (IContributionItem[]) contributions.toArray(new IContributionItem[contributions.size()]); |
|
92 |
} |
|
93 |
|
|
94 |
private void doSetFlagCommand(MarkerType markerType, boolean flag) { |
|
95 |
try { |
|
96 |
IHandlerService handlerService = |
|
97 |
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); |
|
98 |
Event event = new Event(); |
|
99 |
event.data = markerType; |
|
100 |
if (flag) { |
|
101 |
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagTrue", event); |
|
102 |
} else { |
|
103 |
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagFalse", event); |
|
104 |
} |
|
105 |
} catch (Exception e) { |
|
106 |
// TODO Auto-generated catch block |
|
107 |
e.printStackTrace(); |
|
108 |
} |
|
109 |
} |
|
110 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation