blob: d6cc2220a5299059f9bc4601c27b4c7144f3dd2f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.common.handlers;
import java.util.Hashtable;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
import org.eclipse.papyrus.infra.nattable.nattableconfiguration.NattableConfigurationRegistry;
/**
* The handler used to create a nattable editor
*
* @author Vincent Lorenzo
*
*/
public class CreateNatTableEditorHandler extends AbstractCreateNattableEditorHandler implements IExecutableExtension {
/**
* the name of the parameter of the handler
*/
private static final String TABLE_TYPE_PARAMETER = "tableType"; //$NON-NLS-1$
/**
* the type of the table to create
*/
private String type;
/**
*
* Constructor.
*
*/
public CreateNatTableEditorHandler() {
super();
}
/**
* Set the type of table to be created by this handler
*
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
*
* @see org.eclipse.papyrus.infra.nattable.common.handlers.AbstractCreateNattableEditorHandler2#getTableEditorConfiguration()
*
* @return
*/
@Override
protected TableConfiguration getTableEditorConfiguration() {
return NattableConfigurationRegistry.INSTANCE.getConfiguration(this.type);
}
/**
*
* @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
*
* @param evaluationContext
*/
@Override
public void setEnabled(Object evaluationContext) {
if (this.type != null) {
List<EObject> selection = getSelection();
if (selection.size() == 1) {
IStatus status = NattableConfigurationRegistry.INSTANCE.canCreateTable(this.type, selection.get(0));
setBaseEnabled(status.isOK());
return;
}
}
setBaseEnabled(false);
}
/**
*
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
*
* @param config
* @param propertyName
* @param data
* @throws CoreException
*/
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
if (data instanceof Hashtable) {
this.type = (String) ((Hashtable<?, ?>) data).get(TABLE_TYPE_PARAMETER);
}
}
}
|