View | Details | Raw Unified | Return to bug 128779 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/internal/graphdef/codegen/ui/ConverterSection.java (-2 / +44 lines)
Lines 61-76 Link Here
61
	public static final String OPTION_MAIN_PACKAGE_NAME = SECTION_ID + ".mainPackageName";
61
	public static final String OPTION_MAIN_PACKAGE_NAME = SECTION_ID + ".mainPackageName";
62
	public static final String OPTION_NEEDS_MAP_MODE = SECTION_ID + ".needsMapMode";
62
	public static final String OPTION_NEEDS_MAP_MODE = SECTION_ID + ".needsMapMode";
63
	public static final String OPTION_INPUT_RESOURCE_FULL_PATH = SECTION_ID + ".inputResource";
63
	public static final String OPTION_INPUT_RESOURCE_FULL_PATH = SECTION_ID + ".inputResource";
64
	public static final String OPTION_OUTPUT_RESOURCE_FULL_PATH = SECTION_ID + ".outputResource";
64
	
65
	
65
	private TemplateOption myPackageNameOption;
66
	private TemplateOption myPackageNameOption;
66
	private FileNameOption myInputPathOption;
67
	private FileNameOption myInputPathOption;
68
	private FileNameOption myOutputGalleryPathOption;
67
	private final CachedInputValidationState myCachedInputValidationState;
69
	private final CachedInputValidationState myCachedInputValidationState;
68
	private ManifestElement[] myRequiredBundles;
70
	private ManifestElement[] myRequiredBundles;
69
	
71
	
70
	public ConverterSection(){
72
	public ConverterSection(){
71
		setPageCount(THE_ONLY_PAGE_INDEX + 1);
73
		setPageCount(THE_ONLY_PAGE_INDEX + 1);
72
		myPackageNameOption = addOption(OPTION_MAIN_PACKAGE_NAME, "Generate figures package", null, THE_ONLY_PAGE_INDEX);
74
		myPackageNameOption = addOption(OPTION_MAIN_PACKAGE_NAME, "Generate figures package", null, THE_ONLY_PAGE_INDEX);
73
		myInputPathOption = addFileNameOption(OPTION_INPUT_RESOURCE_FULL_PATH, "Input GMFGraph instance", "", THE_ONLY_PAGE_INDEX);
75
		myInputPathOption = addFileNameOption(false, OPTION_INPUT_RESOURCE_FULL_PATH, "Input GMFGraph instance", "", THE_ONLY_PAGE_INDEX);
76
		myOutputGalleryPathOption = addFileNameOption(true, OPTION_OUTPUT_RESOURCE_FULL_PATH, "Create Figure Gallery", "", THE_ONLY_PAGE_INDEX);
77
		myOutputGalleryPathOption.setRequired(false);
74
		addOption(OPTION_NEEDS_MAP_MODE, "Use IMapMode", false, THE_ONLY_PAGE_INDEX);
78
		addOption(OPTION_NEEDS_MAP_MODE, "Use IMapMode", false, THE_ONLY_PAGE_INDEX);
75
		myCachedInputValidationState = new CachedInputValidationState();
79
		myCachedInputValidationState = new CachedInputValidationState();
76
	}
80
	}
Lines 84-89 Link Here
84
		markPagesAdded();
88
		markPagesAdded();
85
		validateOptions(myPackageNameOption);
89
		validateOptions(myPackageNameOption);
86
		validateOptions(myInputPathOption);
90
		validateOptions(myInputPathOption);
91
		validateOptions(myOutputGalleryPathOption);
87
	}
92
	}
88
93
89
	public IPluginReference[] getDependencies(String schemaVersion) {
94
	public IPluginReference[] getDependencies(String schemaVersion) {
Lines 118-123 Link Here
118
		if (!generator.getRunStatus().isOK()){
123
		if (!generator.getRunStatus().isOK()){
119
			throw new CoreException(generator.getRunStatus());
124
			throw new CoreException(generator.getRunStatus());
120
		}
125
		}
126
		createFigureGallery(generator.getGenerationInfo());
127
	}
128
	
129
	private void createFigureGallery(StandaloneGenerator.GenerationInfo info) throws CoreException {
130
		if (!myOutputGalleryPathOption.isEmpty()){
131
			String path = myOutputGalleryPathOption.getText();
132
			Resource galleryResource = new ResourceSetImpl().createResource(URI.createFileURI(path));
133
			galleryResource.getContents().add(new StandaloneGalleryConverter().convertFigureGallery(info));
134
			try {
135
				galleryResource.save(null);
136
			} catch (IOException e) {
137
				throw new CoreException(new Status(//
138
						IStatus.ERROR, MY_PLUGIN_ID, 0, e.getMessage(), e
139
				));
140
			}
141
		}
121
	}
142
	}
122
	
143
	
123
	private void readRequiredBundles() throws CoreException, IOException {
144
	private void readRequiredBundles() throws CoreException, IOException {
Lines 190-195 Link Here
190
		if (!validateInputPath()){
211
		if (!validateInputPath()){
191
			return;
212
			return;
192
		}
213
		}
214
		if (!validateOutputGalleryPath()){
215
			return;
216
		}
193
		resetPageState();
217
		resetPageState();
194
	}
218
	}
195
219
Lines 253-260 Link Here
253
		return buffer.toString().toLowerCase(Locale.ENGLISH);
277
		return buffer.toString().toLowerCase(Locale.ENGLISH);
254
	}
278
	}
255
279
256
	private FileNameOption addFileNameOption(String name, String label, String value, int pageIndex) {
280
	private FileNameOption addFileNameOption(boolean saveNotLoad, String name, String label, String value, int pageIndex) {
257
		FileNameOption result = new FileNameOption(this, name, label, new String[] {"*.gmfgraph"});
281
		FileNameOption result = new FileNameOption(this, name, label, new String[] {"*.gmfgraph"});
282
		result.setSaveNotLoad(saveNotLoad);
258
		registerOption(result, value, pageIndex);
283
		registerOption(result, value, pageIndex);
259
		return result;
284
		return result;
260
	}
285
	}
Lines 281-286 Link Here
281
		}
306
		}
282
		return true;
307
		return true;
283
	}
308
	}
309
	
310
	private boolean validateOutputGalleryPath() {
311
		if (myOutputGalleryPathOption.isEmpty()){
312
			//optional -- ok
313
			return true;
314
		}
315
		String path = myOutputGalleryPathOption.getText();
316
		try {
317
			URI.createFileURI(path);
318
		} catch (IllegalArgumentException e){
319
			String message = MessageFormat.format("Path {0} is invalid", new Object[] {path});
320
			getTheOnlyPage().setPageComplete(false);
321
			getTheOnlyPage().setErrorMessage(message);
322
			return false;
323
		}
324
		return true;
325
	}
284
326
285
	private WizardPage getTheOnlyPage() {
327
	private WizardPage getTheOnlyPage() {
286
		return getPage(THE_ONLY_PAGE_INDEX);
328
		return getPage(THE_ONLY_PAGE_INDEX);
(-)src/org/eclipse/gmf/internal/graphdef/codegen/ui/FileNameOption.java (-2 / +15 lines)
Lines 36-41 Link Here
36
	private Label myLabelControl;
36
	private Label myLabelControl;
37
	private Button myBrowseButton;
37
	private Button myBrowseButton;
38
	private boolean myIgnoreListener;
38
	private boolean myIgnoreListener;
39
	private boolean mySaveNotLoad;
39
	
40
	
40
	/**
41
	/**
41
	 * @param section
42
	 * @param section
Lines 51-56 Link Here
51
		myExtensions = extensions;
52
		myExtensions = extensions;
52
	}
53
	}
53
	
54
	
55
	public void setSaveNotLoad(boolean saveNotLoad){
56
		mySaveNotLoad = saveNotLoad;
57
	}
58
	
54
	/**
59
	/**
55
	 * A utility version of the <samp>getValue() </samp> method that converts
60
	 * A utility version of the <samp>getValue() </samp> method that converts
56
	 * the current value into the String object.
61
	 * the current value into the String object.
Lines 109-115 Link Here
109
		groupLayout.marginWidth = 0;
114
		groupLayout.marginWidth = 0;
110
		groupLayout.marginHeight = 0;
115
		groupLayout.marginHeight = 0;
111
		groupLayout.verticalSpacing = 0;
116
		groupLayout.verticalSpacing = 0;
112
		groupLayout.horizontalSpacing = 0;
117
		groupLayout.horizontalSpacing = 5;
113
		textAndButtonGroup.setLayout(groupLayout);
118
		textAndButtonGroup.setLayout(groupLayout);
114
119
115
		GridData groupLayoutData = new GridData(GridData.FILL_HORIZONTAL);
120
		GridData groupLayoutData = new GridData(GridData.FILL_HORIZONTAL);
Lines 145-155 Link Here
145
			}
150
			}
146
		
151
		
147
			public void widgetSelected(SelectionEvent e) {
152
			public void widgetSelected(SelectionEvent e) {
148
				FileDialog fileDialog = new FileDialog(e.display.getActiveShell(), SWT.PRIMARY_MODAL | SWT.OPEN);
153
				FileDialog fileDialog = new FileDialog(e.display.getActiveShell(), getSaveNotLoadDialogStyle() | SWT.PRIMARY_MODAL);
149
				fileDialog.setFilterExtensions(myExtensions);
154
				fileDialog.setFilterExtensions(myExtensions);
150
				setText(fileDialog.open());
155
				setText(fileDialog.open());
151
				getSection().validateOptions(FileNameOption.this);
156
				getSection().validateOptions(FileNameOption.this);
152
			}
157
			}
158
			
159
			private int getSaveNotLoadDialogStyle(){
160
				return FileNameOption.this.isSaveNotLoad() ? SWT.SAVE : SWT.OPEN;
161
			}
153
		});
162
		});
154
	}
163
	}
155
164
Lines 176-179 Link Here
176
			myBrowseButton.setEnabled(enabled);
185
			myBrowseButton.setEnabled(enabled);
177
		}
186
		}
178
	}
187
	}
188
	
189
	private boolean isSaveNotLoad(){
190
		return mySaveNotLoad;
191
	}
179
}
192
}
(-)src/org/eclipse/gmf/internal/graphdef/codegen/ui/StandaloneGalleryConverter.java (+54 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.internal.graphdef.codegen.ui;
14
15
import java.util.Enumeration;
16
17
import org.eclipse.gmf.gmfgraph.ConnectionFigure;
18
import org.eclipse.gmf.gmfgraph.CustomFigure;
19
import org.eclipse.gmf.gmfgraph.DecorationFigure;
20
import org.eclipse.gmf.gmfgraph.Figure;
21
import org.eclipse.gmf.gmfgraph.FigureGallery;
22
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
23
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator;
24
25
public class StandaloneGalleryConverter {
26
	public FigureGallery convertFigureGallery(StandaloneGenerator.GenerationInfo generationInfo){
27
		FigureGallery result = GMFGraphFactory.eINSTANCE.createFigureGallery();
28
		String generatedBundle = generationInfo.getConfig().getPluginID();
29
		result.setImplementationBundle(generatedBundle);
30
		
31
		for (Enumeration originalFigures = generationInfo.getProcessedFigures(); originalFigures.hasMoreElements();){
32
			Figure nextOriginal = (Figure) originalFigures.nextElement();
33
			String nextConvertedFqn = generationInfo.getGeneratedClassFQN(nextOriginal);
34
			CustomFigure custom = createCustomFigure(nextOriginal);
35
			custom.setBundleName(generatedBundle);
36
			custom.setQualifiedClassName(nextConvertedFqn);
37
			
38
			result.getFigures().add(custom);
39
		}
40
		return result;
41
	}
42
	
43
	private CustomFigure createCustomFigure(Figure original){
44
		GMFGraphFactory factory = GMFGraphFactory.eINSTANCE;
45
		if (original instanceof DecorationFigure){
46
			return factory.createCustomDecoration();
47
		} 
48
		if (original instanceof ConnectionFigure){
49
			return factory.createCustomConnection();
50
		}
51
		return factory.createCustomFigure();
52
	}
53
54
}
(-)src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java (-8 / +56 lines)
Lines 14-22 Link Here
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Arrays;
15
import java.util.Arrays;
16
import java.util.Collections;
16
import java.util.Collections;
17
import java.util.Enumeration;
17
import java.util.HashSet;
18
import java.util.HashSet;
19
import java.util.IdentityHashMap;
18
import java.util.Iterator;
20
import java.util.Iterator;
19
import java.util.List;
21
import java.util.List;
22
import java.util.Map;
20
23
21
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Path;
Lines 36-41 Link Here
36
	private final StandaloneEmitters myAuxiliaryGenerators;
39
	private final StandaloneEmitters myAuxiliaryGenerators;
37
	private boolean mySkipPluginStructire;
40
	private boolean mySkipPluginStructire;
38
	private final FigureQualifiedNameSwitch myFigureNameSwitch;
41
	private final FigureQualifiedNameSwitch myFigureNameSwitch;
42
	private final GenerationInfoImpl myGenerationInfo;
43
	
44
	public interface GenerationInfo {
45
		public Config getConfig(); 
46
		public Enumeration/*<Figure>*/ getProcessedFigures();
47
		public String getGeneratedClassFQN(Figure figure);
48
	}
39
	
49
	
40
	public interface Config {
50
	public interface Config {
41
		public String getPluginID();
51
		public String getPluginID();
Lines 117-122 Link Here
117
				new FigureGenerator(getPackageName(), importAssistant, fqnSwitch, strategy)
127
				new FigureGenerator(getPackageName(), importAssistant, fqnSwitch, strategy)
118
		);
128
		);
119
		myAuxiliaryGenerators = new StandaloneEmitters();
129
		myAuxiliaryGenerators = new StandaloneEmitters();
130
		myGenerationInfo = new GenerationInfoImpl(myArgs);
131
	}
132
	
133
	public GenerationInfo getGenerationInfo() {
134
		return myGenerationInfo;
120
	}
135
	}
121
	
136
	
122
	/**
137
	/**
Lines 127-138 Link Here
127
		mySkipPluginStructire = skipManifest;
142
		mySkipPluginStructire = skipManifest;
128
	}
143
	}
129
	
144
	
130
	private static String composePluginActivatorClassFQN(Config config) {
131
		String packageName = config.getPluginActivatorPackageName();
132
		String className = config.getPluginActivatorClassName();
133
		return packageName == null || "".equals(packageName) ? className : packageName + "." + className; 
134
	}
135
136
	protected void setupProgressMonitor() {
145
	protected void setupProgressMonitor() {
137
		//setupProgressMonitor("Generating GMFGraph plugin", 100);
146
		//setupProgressMonitor("Generating GMFGraph plugin", 100);
138
	}
147
	}
Lines 187-199 Link Here
187
	}
196
	}
188
	
197
	
189
	private void visitFigure(Figure figure) throws InterruptedException {
198
	private void visitFigure(Figure figure) throws InterruptedException {
190
		doGenerateJavaClass(myFigureGenerator, getPackageName(), figure.getName(), figure);
199
		String packageName = getPackageName();
200
		String className = figure.getName();
201
		doGenerateJavaClass(myFigureGenerator, packageName, className, figure);
202
		myGenerationInfo.registerFQN(figure, composeFQN(packageName, className));
191
	}
203
	}
192
204
	
193
	private String getPackageName(){
205
	private String getPackageName(){
194
		return myArgs.getMainPackageName();
206
		return myArgs.getMainPackageName();
195
	}
207
	}
208
	
209
	private static String composePluginActivatorClassFQN(Config config) {
210
		String packageName = config.getPluginActivatorPackageName();
211
		String className = config.getPluginActivatorClassName();
212
		return composeFQN(packageName, className);
213
	}
196
214
215
	private static String composeFQN(String packageName, String className){
216
		return packageName == null || "".equals(packageName) ? className : packageName + "." + className; 
217
	}
218
	
197
	private static class FigureGeneratorAdapter implements GeneratorBase.Emitter {
219
	private static class FigureGeneratorAdapter implements GeneratorBase.Emitter {
198
		private final FigureGenerator myDelegate;
220
		private final FigureGenerator myDelegate;
199
221
Lines 209-212 Link Here
209
		}
231
		}
210
	}
232
	}
211
	
233
	
234
	private static class GenerationInfoImpl implements GenerationInfo {
235
		private final Map myFigure2FQN = new IdentityHashMap();
236
		private final Config myConfig;
237
		
238
		public GenerationInfoImpl(Config config){
239
			myConfig = config;
240
		}
241
		
242
		public Config getConfig() {
243
			return myConfig;
244
		}
245
		
246
		public void registerFQN(Figure figure, String fqn){
247
			myFigure2FQN.put(figure, fqn);
248
		}
249
		
250
		public String getGeneratedClassFQN(Figure figure) {
251
			return (String)myFigure2FQN.get(figure);
252
		}
253
		
254
		public Enumeration getProcessedFigures() {
255
			return Collections.enumeration(myFigure2FQN.keySet());
256
		}
257
		
258
	}
259
	
212
}
260
}

Return to bug 128779