Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313179 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/papyrus/wizards/template/ModelTemplateDescription.java (+109 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.wizards.template;
15
16
/**
17
 * The Class ModelTemplateDescription.
18
 */
19
public class ModelTemplateDescription {
20
21
	/** The name. */
22
	private String name;
23
24
	// private String metamodelURI;
25
	/** The path. */
26
	private String path;
27
28
	/** The plugin id. */
29
	private String pluginId;
30
31
	/** The language. */
32
	private String language;
33
34
	/**
35
	 * Instantiates a new model template description.
36
	 *
37
	 * @param name the name
38
	 * @param pluginId the plugin id
39
	 * @param path the path
40
	 */
41
	public ModelTemplateDescription(String name, String pluginId, String path) {
42
		super();
43
		this.name = name;
44
		// this.e = metamodelURI;
45
		this.path = path;
46
		this.pluginId = pluginId;
47
	}
48
49
	/**
50
	 * Sets the language.
51
	 *
52
	 * @param language the new language
53
	 */
54
	public void setLanguage(String language) {
55
		this.language = language;
56
	}
57
58
	/**
59
	 * Gets the name.
60
	 *
61
	 * @return the name
62
	 */
63
	public String getName() {
64
		return name;
65
	}
66
67
	// /**
68
	// * @return the metamodelURI
69
	// */
70
	// public String getMetamodelURI() {
71
	// return metamodelURI;
72
	// }
73
74
	/**
75
	 * @return the path
76
	 */
77
	public String getPath() {
78
		return path;
79
	}
80
81
	/**
82
	 * Gets the file name.
83
	 *
84
	 * @return the file name
85
	 */
86
	public String getFileName() {
87
		String[] pathParts = path.split("/");
88
		return pathParts[pathParts.length - 1];
89
	}
90
91
	/**
92
	 * Gets the plugin id.
93
	 *
94
	 * @return the plugin id
95
	 */
96
	public String getPluginId() {
97
		return pluginId;
98
	}
99
100
	/**
101
	 * Gets the language.
102
	 *
103
	 * @return the language
104
	 */
105
	public String getLanguage() {
106
		return language;
107
	}
108
109
}
(-)src/org/eclipse/papyrus/wizards/template/ModelTemplatesContentProvider.java (+121 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.wizards.template;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.List;
19
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IExtension;
22
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jface.viewers.IStructuredContentProvider;
25
import org.eclipse.jface.viewers.TableViewer;
26
import org.eclipse.jface.viewers.Viewer;
27
28
/**
29
 * The Class ModelTemplatesContentProvider.
30
 */
31
public class ModelTemplatesContentProvider implements IStructuredContentProvider {
32
33
	/** The Constant EXTENSION_POINT_ID. */
34
	private static final String EXTENSION_POINT_ID = "org.eclipse.papyrus.wizards.templates";
35
36
	/** The Constant ATTRIBUTE_NAME. */
37
	private static final String ATTRIBUTE_NAME = "name";
38
39
	/** The Constant ATTRIBUTE_FILE. */
40
	private static final String ATTRIBUTE_FILE = "file";
41
42
	/** The Constant ATTRIBUTE_LANGUAGE. */
43
	private static final String ATTRIBUTE_LANGUAGE = "language";
44
45
	/**
46
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
47
	 *
48
	 */
49
	public void dispose() {
50
		// TODO Auto-generated method stub
51
52
	}
53
54
	/**
55
	 * Gets the templates description.
56
	 *
57
	 * @return the templates description
58
	 */
59
	private ModelTemplateDescription[] getTemplatesDescription() {
60
		List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
61
62
		IExtensionRegistry registry = Platform.getExtensionRegistry();
63
		IExtension[] extensions = registry.getExtensionPoint(EXTENSION_POINT_ID).getExtensions();
64
65
		for(IExtension extension : extensions) {
66
			templates.addAll(processExtension(extension));
67
		}
68
69
		return templates.toArray(new ModelTemplateDescription[templates.size()]);
70
	}
71
72
	/**
73
	 * Process extension.
74
	 *
75
	 * @param extension the extension
76
	 * @return the collection
77
	 */
78
	private Collection<ModelTemplateDescription> processExtension(IExtension extension) {
79
		List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
80
		for(IConfigurationElement configElement : extension.getConfigurationElements()) {
81
			ModelTemplateDescription template = new ModelTemplateDescription(configElement.getAttribute(ATTRIBUTE_NAME), extension.getContributor().getName(), configElement.getAttribute(ATTRIBUTE_FILE));
82
			template.setLanguage(configElement.getAttribute(ATTRIBUTE_LANGUAGE));
83
			templates.add(template);
84
		}
85
		return templates;
86
	}
87
88
	/**
89
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
90
	 *
91
	 * @param inputElement
92
	 * @return
93
	 */
94
	public Object[] getElements(Object inputElement) {
95
		if(inputElement instanceof String) {
96
			List<ModelTemplateDescription> result = new ArrayList<ModelTemplateDescription>();
97
			String diagramCategory = (String)inputElement;
98
			for(ModelTemplateDescription template : getTemplatesDescription()) {
99
				if(diagramCategory == null || diagramCategory.equals(template.getLanguage())) {
100
					result.add(template);
101
				}
102
			}
103
			return result.toArray();
104
		}
105
		return new Object[0];
106
	}
107
108
	/**
109
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
110
	 *
111
	 * @param viewer
112
	 * @param oldInput
113
	 * @param newInput
114
	 */
115
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
116
		if(viewer instanceof TableViewer) {
117
			((TableViewer)viewer).add(getElements(null));
118
		}
119
	}
120
121
}
(-)src/org/eclipse/papyrus/wizards/template/ModelTemplatesLabelProvider.java (+89 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.wizards.template;
15
16
import org.eclipse.jface.viewers.ILabelProviderListener;
17
import org.eclipse.jface.viewers.ITableLabelProvider;
18
import org.eclipse.swt.graphics.Image;
19
20
/**
21
 * The Class ModelTemplatesLabelProvider.
22
 */
23
public class ModelTemplatesLabelProvider implements ITableLabelProvider {
24
25
	/**
26
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
27
	 * 
28
	 * @param element
29
	 * @param columnIndex
30
	 * @return
31
	 */
32
	public Image getColumnImage(Object element, int columnIndex) {
33
		return null;
34
	}
35
36
	/**
37
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
38
	 * 
39
	 * @param element
40
	 * @param columnIndex
41
	 * @return
42
	 */
43
	public String getColumnText(Object element, int columnIndex) {
44
		if(element instanceof ModelTemplateDescription) {
45
			ModelTemplateDescription modelTemplate = (ModelTemplateDescription)element;
46
			return modelTemplate.getName() + " (" + modelTemplate.getFileName() + ")";
47
		}
48
		return null;
49
	}
50
51
	/**
52
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
53
	 *
54
	 * @param listener
55
	 */
56
	public void addListener(ILabelProviderListener listener) {
57
58
	}
59
60
	/**
61
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
62
	 *
63
	 */
64
	public void dispose() {
65
66
	}
67
68
	/**
69
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
70
	 *
71
	 * @param element
72
	 * @param property
73
	 * @return
74
	 */
75
	public boolean isLabelProperty(Object element, String property) {
76
77
		return false;
78
	}
79
80
	/**
81
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
82
	 *
83
	 * @param listener
84
	 */
85
	public void removeListener(ILabelProviderListener listener) {
86
87
	}
88
89
}
(-)src/org/eclipse/papyrus/wizards/template/SelectModelTemplateComposite.java (+178 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.wizards.template;
15
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.jface.viewers.TableViewer;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Group;
27
28
29
/**
30
 * The Class SelectModelTemplateComposite.
31
 */
32
public class SelectModelTemplateComposite extends Composite {
33
	
34
	/** The new model button. */
35
	private Button newModelButton;
36
37
	/** The template table viewer. */
38
	private TableViewer templateTableViewer;
39
	
40
	/** The use template button. */
41
	private Button useTemplateButton;
42
43
	/**
44
	 * Instantiates a new select model template composite.
45
	 *
46
	 * @param parent the parent
47
	 */
48
	public SelectModelTemplateComposite(Composite parent) {
49
		super(parent, SWT.NONE);
50
		setLayout(new GridLayout());
51
		
52
		Group composite = new Group(this, 0);
53
		composite.setText("Creation  approach");
54
55
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
56
		GridLayout gridLayout = new GridLayout(1, false);
57
		gridLayout.marginWidth = 20;
58
		gridLayout.marginTop = 10;
59
		gridLayout.verticalSpacing = 10;
60
		composite.setLayout(gridLayout);
61
		createDialogArea(composite);
62
	}
63
	
64
	/**
65
	 * Creates the dialog area.
66
	 *
67
	 * @param composite the composite
68
	 */
69
	private void createDialogArea(Composite composite) {
70
		createApproachSelectionButtons(composite);
71
		createTemplatesViewer(composite);
72
	}
73
74
	/**
75
	 * Creates the templates viewer.
76
	 *
77
	 * @param composite the composite
78
	 */
79
	private void createTemplatesViewer(Composite composite) {
80
		GridData data = new GridData(GridData.FILL_BOTH);
81
		templateTableViewer = new TableViewer(composite);
82
		templateTableViewer.getTable().setLayoutData(data);
83
84
		templateTableViewer.setContentProvider(new ModelTemplatesContentProvider());
85
		templateTableViewer.setLabelProvider(new ModelTemplatesLabelProvider());
86
		if(templateTableViewer.getTable().getItemCount() > 0) {
87
			IStructuredSelection ss = new StructuredSelection(templateTableViewer.getElementAt(0));
88
			templateTableViewer.setSelection(ss);
89
		} else {
90
			useTemplateButton.setEnabled(true);
91
		}
92
		templateTableViewer.getControl().setEnabled(false);
93
	}
94
95
	/**
96
	 * Creates the approach selection buttons.
97
	 *
98
	 * @param composite the composite
99
	 */
100
	private void createApproachSelectionButtons(Composite composite) {
101
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
102
		newModelButton = new Button(composite, SWT.RADIO);
103
		newModelButton.setText("Create new model");
104
		newModelButton.setLayoutData(data);
105
		newModelButton.setSelection(true);
106
107
		data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
108
		useTemplateButton = new Button(composite, SWT.RADIO);
109
		useTemplateButton.setText("Initialize from template");
110
		useTemplateButton.setLayoutData(data);
111
		useTemplateButton.setSelection(false);
112
113
		useTemplateButton.addSelectionListener(new SelectionListener() {
114
115
			public void widgetDefaultSelected(SelectionEvent e) {
116
				// TODO Auto-generated method stub
117
118
			}
119
120
			public void widgetSelected(SelectionEvent e) {
121
				if(useTemplateButton.getSelection()) {
122
					templateTableViewer.getControl().setEnabled(true);
123
				} else {
124
					templateTableViewer.getControl().setEnabled(false);
125
				}
126
			}
127
128
		});
129
130
	}
131
	
132
	/**
133
	 * Gets the template path.
134
	 *
135
	 * @return the template path
136
	 */
137
	public String getTemplatePath() {
138
		if(this.useTemplateButton.getSelection()) {
139
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
140
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
141
				if(first instanceof ModelTemplateDescription) {
142
					return ((ModelTemplateDescription)first).getPath();
143
				}
144
			}
145
		}
146
147
		return null;
148
	}
149
	
150
	/**
151
	 * Gets the template plugin id.
152
	 *
153
	 * @return the template plugin id
154
	 */
155
	public String getTemplatePluginId() {
156
		if(this.useTemplateButton.getSelection()) {
157
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
158
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
159
				if(first instanceof ModelTemplateDescription) {
160
					return ((ModelTemplateDescription)first).getPluginId();
161
				}
162
			}
163
		}
164
165
		return null;
166
	}
167
168
	/**
169
	 * Sets the input.
170
	 *
171
	 * @param input the new input
172
	 */
173
	public void setInput(Object input) {
174
		templateTableViewer.setInput(input);
175
	}
176
177
}	
178
	
(-)src/org/eclipse/papyrus/wizards/SelectTemplateWizardPage.java (-275 / +39 lines)
Lines 13-25 Link Here
13
package org.eclipse.papyrus.wizards;
13
package org.eclipse.papyrus.wizards;
14
14
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Collection;
17
import java.util.List;
16
import java.util.List;
18
17
19
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IExtension;
22
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.core.runtime.Platform;
Lines 30-42 Link Here
30
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
26
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
31
import org.eclipse.emf.ecore.util.EcoreUtil;
27
import org.eclipse.emf.ecore.util.EcoreUtil;
32
import org.eclipse.emf.transaction.RecordingCommand;
28
import org.eclipse.emf.transaction.RecordingCommand;
33
import org.eclipse.jface.viewers.ILabelProviderListener;
34
import org.eclipse.jface.viewers.IStructuredContentProvider;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.viewers.ITableLabelProvider;
37
import org.eclipse.jface.viewers.StructuredSelection;
38
import org.eclipse.jface.viewers.TableViewer;
39
import org.eclipse.jface.viewers.Viewer;
40
import org.eclipse.jface.wizard.IWizardPage;
29
import org.eclipse.jface.wizard.IWizardPage;
41
import org.eclipse.jface.wizard.WizardPage;
30
import org.eclipse.jface.wizard.WizardPage;
42
import org.eclipse.papyrus.core.utils.DiResourceSet;
31
import org.eclipse.papyrus.core.utils.DiResourceSet;
Lines 44-58 Link Here
44
import org.eclipse.papyrus.resource.notation.NotationModel;
33
import org.eclipse.papyrus.resource.notation.NotationModel;
45
import org.eclipse.papyrus.resource.sasheditor.DiModel;
34
import org.eclipse.papyrus.resource.sasheditor.DiModel;
46
import org.eclipse.papyrus.resource.uml.UmlModel;
35
import org.eclipse.papyrus.resource.uml.UmlModel;
47
import org.eclipse.swt.SWT;
36
import org.eclipse.papyrus.wizards.template.SelectModelTemplateComposite;
48
import org.eclipse.swt.events.SelectionEvent;
49
import org.eclipse.swt.events.SelectionListener;
50
import org.eclipse.swt.graphics.Image;
51
import org.eclipse.swt.layout.GridData;
52
import org.eclipse.swt.layout.GridLayout;
53
import org.eclipse.swt.widgets.Button;
54
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Composite;
55
import org.eclipse.swt.widgets.Group;
56
38
57
/**
39
/**
58
 * A wizard page that allows the selection of template models contributed via an
40
 * A wizard page that allows the selection of template models contributed via an
Lines 64-118 Link Here
64
 */
46
 */
65
public class SelectTemplateWizardPage extends WizardPage {
47
public class SelectTemplateWizardPage extends WizardPage {
66
48
67
	private Button newModelButton;
49
	/** The select template composite. */
68
50
	private SelectModelTemplateComposite selectTemplateComposite;
69
	private Button useTemplateButton;
70
71
	private TableViewer templateTableViewer;
72
73
	private String editorId;
74
51
52
	/**
53
	 * Instantiates a new select template wizard page.
54
	 *
55
	 * @param pageName the page name
56
	 */
75
	protected SelectTemplateWizardPage(String pageName) {
57
	protected SelectTemplateWizardPage(String pageName) {
76
		super(pageName);
58
		super(pageName);
77
		// TODO Auto-generated constructor stub
78
	}
59
	}
79
60
61
	/**
62
	 * Instantiates a new select template wizard page.
63
	 *
64
	 * @param editorId the editor id
65
	 * @param nextPage the next page
66
	 * @param templatePage the template page
67
	 */
80
	public SelectTemplateWizardPage(String editorId, WizardPage nextPage, WizardPage templatePage) {
68
	public SelectTemplateWizardPage(String editorId, WizardPage nextPage, WizardPage templatePage) {
81
		super("Select creation approach");
69
		super("Select creation approach");
82
		this.setTitle("Select creation approach");
70
		this.setTitle("Select creation approach");
83
		this.setDescription("Diagrams can be created from scratch or from a template");
71
		this.setDescription("Diagrams can be created from scratch or from a template");
84
		this.editorId = editorId;
85
	}
72
	}
86
73
87
	public String getTemplatePath() {
88
		if(this.useTemplateButton.getSelection()) {
89
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
90
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
91
				if(first instanceof ModelTemplateDescription) {
92
					return ((ModelTemplateDescription)first).getPath();
93
				}
94
			}
95
		}
96
97
		return null;
98
	}
99
100
	public String getTemplatePluginId() {
101
		if(this.useTemplateButton.getSelection()) {
102
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
103
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
104
				if(first instanceof ModelTemplateDescription) {
105
					return ((ModelTemplateDescription)first).getPluginId();
106
				}
107
			}
108
		}
109
74
110
		return null;
75
	/**
111
	}
76
	 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
77
	 *
78
	 * @param visible
79
	 */
112
	@Override
80
	@Override
113
	public void setVisible(boolean visible) {
81
	public void setVisible(boolean visible) {
114
		super.setVisible(visible);
82
		super.setVisible(visible);
115
		templateTableViewer.setInput(getDiagramCategory());
83
		selectTemplateComposite.setInput(getDiagramCategory());
116
	}
84
	}
117
	
85
	
118
	/**
86
	/**
Lines 128-204 Link Here
128
		return ((SelectDiagramCategoryPage)previousPage).getDiagramCategory();
96
		return ((SelectDiagramCategoryPage)previousPage).getDiagramCategory();
129
	}
97
	}
130
98
99
	/**
100
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
101
	 *
102
	 * @param parent
103
	 */
131
	public void createControl(Composite parent) {
104
	public void createControl(Composite parent) {
132
		Composite root = new Composite(parent, SWT.NONE);
105
		selectTemplateComposite = new SelectModelTemplateComposite(parent);
133
		GridLayout gridLayout = new GridLayout();
106
		setControl(selectTemplateComposite);
134
		root.setLayout(gridLayout);
135
		Group composite = new Group(root, 0);
136
		composite.setText("Creation  approach");
137
138
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
139
		gridLayout = new GridLayout(1, false);
140
		gridLayout.marginWidth = 20;
141
		gridLayout.marginTop = 10;
142
		gridLayout.verticalSpacing = 10;
143
		composite.setLayout(gridLayout);
144
		createDialogArea(composite);
145
146
		setControl(root);
147
	}
148
149
	private void createDialogArea(Composite composite) {
150
		createApproachSelectionButtons(composite);
151
		createTemplatesViewer(composite);
152
	}
153
154
	private void createTemplatesViewer(Composite composite) {
155
		GridData data = new GridData(GridData.FILL_BOTH);
156
		templateTableViewer = new TableViewer(composite);
157
		templateTableViewer.getTable().setLayoutData(data);
158
159
		templateTableViewer.setContentProvider(new ModelTemplatesContentProvider());
160
		templateTableViewer.setLabelProvider(new ModelTemplatesLabelProvider());
161
		if(templateTableViewer.getTable().getItemCount() > 0) {
162
			IStructuredSelection ss = new StructuredSelection(templateTableViewer.getElementAt(0));
163
			templateTableViewer.setSelection(ss);
164
		} else {
165
			useTemplateButton.setEnabled(false);
166
		}
167
		templateTableViewer.getControl().setEnabled(false);
168
	}
107
	}
169
108
170
	private void createApproachSelectionButtons(Composite composite) {
171
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
172
		newModelButton = new Button(composite, SWT.RADIO);
173
		newModelButton.setText("Create new model");
174
		newModelButton.setLayoutData(data);
175
		newModelButton.setSelection(true);
176
177
		data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
178
		useTemplateButton = new Button(composite, SWT.RADIO);
179
		useTemplateButton.setText("Initialize from template");
180
		useTemplateButton.setLayoutData(data);
181
		useTemplateButton.setSelection(false);
182
183
		useTemplateButton.addSelectionListener(new SelectionListener() {
184
185
			public void widgetDefaultSelected(SelectionEvent e) {
186
				// TODO Auto-generated method stub
187
188
			}
189
109
190
			public void widgetSelected(SelectionEvent e) {
110
	/**
191
				if(useTemplateButton.getSelection()) {
111
	 * Initialize model resource.
192
					templateTableViewer.getControl().setEnabled(true);
112
	 *
193
				} else {
113
	 * @param diResourceSet the di resource set
194
					templateTableViewer.getControl().setEnabled(false);
114
	 * @param newFile the new file
195
				}
115
	 * @param root the root
196
			}
116
	 * @param modelContentType the model content type
197
117
	 * @param modelFileExtension the model file extension
198
		});
118
	 */
199
200
	}
201
202
	public void initializeModelResource(final DiResourceSet diResourceSet, final IFile newFile, final EObject root, final String modelContentType, final String modelFileExtension) {
119
	public void initializeModelResource(final DiResourceSet diResourceSet, final IFile newFile, final EObject root, final String modelContentType, final String modelFileExtension) {
203
		RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
120
		RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
204
121
Lines 258-264 Link Here
258
	 *        the root element name
175
	 *        the root element name
259
	 */
176
	 */
260
	protected void initializeModelResource(Resource resource, String rootElementName) {
177
	protected void initializeModelResource(Resource resource, String rootElementName) {
261
		String templatePath = getTemplatePath();
178
		String templatePath = selectTemplateComposite.getTemplatePath();
262
		boolean initializeFromTemplate = templatePath != null;
179
		boolean initializeFromTemplate = templatePath != null;
263
		if(initializeFromTemplate) {
180
		if(initializeFromTemplate) {
264
			initializeFromTemplate(resource, rootElementName, templatePath);
181
			initializeFromTemplate(resource, rootElementName, templatePath);
Lines 307-313 Link Here
307
	 * @return the resource
224
	 * @return the resource
308
	 */
225
	 */
309
	private Resource loadTemplateResource(String templatePath) {
226
	private Resource loadTemplateResource(String templatePath) {
310
		String templatePluginID = getTemplatePluginId();
227
		String templatePluginID = selectTemplateComposite.getTemplatePluginId();
311
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
228
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
312
		String fullUri = templateURL.getPath();
229
		String fullUri = templateURL.getPath();
313
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
230
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
Lines 319-475 Link Here
319
		return null;
236
		return null;
320
	}
237
	}
321
238
322
323
	private class ModelTemplatesContentProvider implements IStructuredContentProvider {
324
325
		private static final String extensionPointId = "org.eclipse.papyrus.wizards.templates";
326
327
		private static final String ATTRIBUTE_NAME = "name";
328
329
		private static final String ATTRIBUTE_FILE = "file";
330
331
		private static final String ATTRIBUTE_LANGUAGE = "language";
332
333
		public void dispose() {
334
			// TODO Auto-generated method stub
335
336
		}
337
338
		private ModelTemplateDescription[] getTemplatesDescription() {
339
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
340
341
			IExtensionRegistry registry = Platform.getExtensionRegistry();
342
			IExtension[] extensions = registry.getExtensionPoint(extensionPointId).getExtensions();
343
344
			for(IExtension extension : extensions) {
345
				templates.addAll(processExtension(extension));
346
			}
347
348
			return templates.toArray(new ModelTemplateDescription[templates.size()]);
349
		}
350
351
		private Collection<ModelTemplateDescription> processExtension(IExtension extension) {
352
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
353
			for(IConfigurationElement configElement : extension.getConfigurationElements()) {
354
				ModelTemplateDescription template = new ModelTemplateDescription(configElement.getAttribute(ATTRIBUTE_NAME), extension.getContributor().getName(), configElement.getAttribute(ATTRIBUTE_FILE));
355
				template.setLanguage(configElement.getAttribute(ATTRIBUTE_LANGUAGE));
356
				templates.add(template);
357
			}
358
			return templates;
359
		}
360
361
		public Object[] getElements(Object inputElement) {
362
			if(inputElement instanceof String) {
363
				List<ModelTemplateDescription> result = new ArrayList<ModelTemplateDescription>();
364
				String diagramCategory = (String)inputElement;
365
				for(ModelTemplateDescription template : getTemplatesDescription()) {
366
					if(diagramCategory == null || diagramCategory.equals(template.getLanguage())) {
367
						result.add(template);
368
					}
369
				}
370
				return result.toArray();
371
			}
372
			return new Object[0];
373
		}
374
375
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
376
			if(viewer instanceof TableViewer) {
377
				((TableViewer)viewer).add(getElements(null));
378
			}
379
		}
380
381
	}
382
383
	private class ModelTemplateDescription {
384
385
		private String name;
386
387
		// private String metamodelURI;
388
		private String path;
389
390
		private String pluginId;
391
392
		private String language;
393
394
		public ModelTemplateDescription(String name, String pluginId, String path) {
395
			super();
396
			this.name = name;
397
			// this.e = metamodelURI;
398
			this.path = path;
399
			this.pluginId = pluginId;
400
		}
401
402
		public void setLanguage(String language) {
403
			this.language = language;
404
		}
405
406
		/**
407
		 * @return the name
408
		 */
409
		public String getName() {
410
			return name;
411
		}
412
413
		// /**
414
		// * @return the metamodelURI
415
		// */
416
		// public String getMetamodelURI() {
417
		// return metamodelURI;
418
		// }
419
420
		/**
421
		 * @return the path
422
		 */
423
		public String getPath() {
424
			return path;
425
		}
426
427
		public String getFileName() {
428
			String[] pathParts = path.split("/");
429
			return pathParts[pathParts.length - 1];
430
		}
431
432
		public String getPluginId() {
433
			return pluginId;
434
		}
435
436
		public String getLanguage() {
437
			return language;
438
		}
439
440
	}
441
442
	private class ModelTemplatesLabelProvider implements ITableLabelProvider {
443
444
		public Image getColumnImage(Object element, int columnIndex) {
445
			return null;
446
		}
447
448
		public String getColumnText(Object element, int columnIndex) {
449
			if(element instanceof ModelTemplateDescription) {
450
				ModelTemplateDescription modelTemplate = (ModelTemplateDescription)element;
451
				return modelTemplate.getName() + " (" + modelTemplate.getFileName() + ")";
452
			}
453
			return null;
454
		}
455
456
		public void addListener(ILabelProviderListener listener) {
457
458
		}
459
460
		public void dispose() {
461
462
		}
463
464
		public boolean isLabelProperty(Object element, String property) {
465
466
			return false;
467
		}
468
469
		public void removeListener(ILabelProviderListener listener) {
470
471
		}
472
473
	}
474
475
}
239
}

Return to bug 313179