aa07a22adec1f9b9ef8e7cdbb0fdcbb1a3f920c6
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / command / OpenBulkEditorContributionItem.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.HashMap;
15 import java.util.List;
16 import java.util.Map;
17
18 import org.eclipse.jface.action.IContributionItem;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.actions.CompoundContributionItem;
22 import org.eclipse.ui.menus.CommandContributionItem;
23 import org.eclipse.ui.menus.CommandContributionItemParameter;
24
25 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
26 import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues;
27
28 /**
29 * <p>
30 * OpenBulkEditorContributionItem class.
31 * </p>
32 *
33 * @author p.ciardelli
34 * @created 19.08.2009
35 * @version 1.0
36 */
37 public class OpenBulkEditorContributionItem extends CompoundContributionItem {
38
39 /**
40 * <p>
41 * Constructor for OpenBulkEditorContributionItem.
42 * </p>
43 */
44 public OpenBulkEditorContributionItem() {
45 }
46
47 /**
48 * <p>
49 * Constructor for OpenBulkEditorContributionItem.
50 * </p>
51 *
52 * @param id
53 * a {@link java.lang.String} object.
54 */
55 public OpenBulkEditorContributionItem(String id) {
56 super(id);
57 }
58
59 /*
60 * (non-Javadoc)
61 *
62 * @see
63 * org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
64 */
65 /** {@inheritDoc} */
66 @Override
67 protected IContributionItem[] getContributionItems() {
68
69 List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
70
71 Map inputTypeValues = (new BulkEditorInputTypeValues())
72 .getParameterValues();
73 for (Object key : inputTypeValues.keySet()) {
74 contributionItems.add(createContributionItem((String) key,
75 (String) inputTypeValues.get(key)));
76 }
77
78 return contributionItems
79 .toArray(new IContributionItem[contributionItems.size()]);
80 }
81
82 /**
83 * @param key
84 * @param object
85 * @return
86 */
87 private IContributionItem createContributionItem(String label,
88 String inputType) {
89 CommandContributionItemParameter parameter = new CommandContributionItemParameter(
90 PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null,
91 IBulkEditorConstants.DYNAMIC_OPEN_MENU_ID, SWT.NONE);
92
93 parameter.label = label;
94
95 Map parameters = new HashMap();
96 parameters.put(IBulkEditorConstants.INPUT_TYPE_PARAMETER_ID, inputType);
97 parameter.parameters = parameters;
98
99 return new CommandContributionItem(parameter);
100 }
101 }