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

Collapse All | Expand All

(-)plugin.properties (+26 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2005 Borland Software Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     Borland Software Corporation - initial API and implementation
10
###############################################################################
11
pluginName = GMF Pure-GEF Code Generation UI
12
providerName = Eclipse.org
13
14
transform.action=Create generator model...
15
generatecode.action=Generate &pure-GEF diagram code
16
17
generatecode.ok=Code generation completed successfully.
18
generatecode.info=Code generation was successful, although few subtle notes:\n{0}
19
generatecode.warn=There are some non-critical problems with generated code:\n{0}
20
generatecode.err=Errors while generating code:\n{0}
21
generatecode.neveragain=Never show me this dialog again.
22
generatecode.badsrc=Source generator model is not completely ok, would you like to proceed?\n{0}
23
24
transform.err=Problems were encountered in mapping definition
25
transform.warn=There are non-critical issues with mapping definition, would you like to proceed?\n{0}
26
transform.neverwarn=I don't like to get this notification in future.
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.gmf.codegen.lite.ui</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
(-).cvsignore (+1 lines)
Added Link Here
1
bin
(-)src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java (+153 lines)
Added Link Here
1
package org.eclipse.gmf.internal.codegen.lite.popup.actions;
2
3
import java.lang.reflect.InvocationTargetException;
4
5
import org.eclipse.core.resources.IFile;
6
import org.eclipse.core.runtime.CoreException;
7
import org.eclipse.core.runtime.IProgressMonitor;
8
import org.eclipse.core.runtime.IStatus;
9
import org.eclipse.core.runtime.Status;
10
import org.eclipse.emf.common.util.BasicDiagnostic;
11
import org.eclipse.emf.common.util.URI;
12
import org.eclipse.emf.ecore.resource.Resource;
13
import org.eclipse.emf.ecore.resource.ResourceSet;
14
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
15
import org.eclipse.emf.ecore.util.Diagnostician;
16
import org.eclipse.emf.ecore.xmi.XMLResource;
17
import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
18
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
19
import org.eclipse.gmf.codegen.lite.ui.CodegenRcpUiPlugin;
20
import org.eclipse.gmf.internal.codegen.lite.Generator;
21
import org.eclipse.jface.action.IAction;
22
import org.eclipse.jface.dialogs.MessageDialog;
23
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
24
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
25
import org.eclipse.jface.operation.IRunnableWithProgress;
26
import org.eclipse.jface.preference.IPreferenceStore;
27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.ui.IObjectActionDelegate;
31
import org.eclipse.ui.IWorkbenchPart;
32
33
public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableWithProgress {
34
	private static final String ASK_INFO = "ask_info";
35
	private static final String ASK_OK = "ask_ok";
36
37
	private IFile mySelection;
38
39
	private IWorkbenchPart myPart;
40
41
	private IStatus myRunStatus;
42
	private GenEditorGenerator myGenModel;
43
44
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
45
		myPart = targetPart;
46
	}
47
48
	// TODO Jobs
49
	public void run(IAction action) {
50
			loadGenModel();
51
			assert getGenModel() != null;
52
			IStatus isGenModelValid = validateGenModel();
53
			if (!isGenModelValid.isOK()) {
54
				if (!MessageDialog.openConfirm(getShell(), action.getText(), formatMessage("generatecode.badsrc", isGenModelValid))) {
55
					return;
56
				}
57
			}
58
			
59
		try {
60
			myRunStatus = Status.CANCEL_STATUS;
61
			new ProgressMonitorDialog(getShell()).run(true, true, this);
62
		} catch (InvocationTargetException ex) {
63
			Throwable targetException = ex.getTargetException();
64
			if (targetException instanceof CoreException) {
65
				myRunStatus = ((CoreException)targetException).getStatus();
66
			} else {
67
				myRunStatus = new Status(IStatus.ERROR, CodegenRcpUiPlugin.getPluginID(), 0, "Exception occurred while generating code", targetException);
68
			}
69
		} catch (InterruptedException ex) {
70
			myRunStatus = Status.CANCEL_STATUS;
71
		} finally {
72
			unloadGenModel();
73
		}
74
		if (getRunStatus().isOK()) {
75
			if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_OK))) {
76
				MessageDialogWithToggle.openInformation(getShell(), action.getText(), CodegenRcpUiPlugin.getBundleString("generatecode.ok"), CodegenRcpUiPlugin.getBundleString("generatecode.neveragain"), false, getPreferences(), ASK_OK);
77
			}
78
		} else if (myRunStatus.matches(IStatus.ERROR)) {
79
			CodegenRcpUiPlugin.getDefault().getLog().log(getRunStatus());
80
			MessageDialog.openError(getShell(), action.getText(), formatMessage("generatecode.err", getRunStatus()));
81
		} else if (myRunStatus.matches(IStatus.WARNING)) {
82
			MessageDialog.openWarning(getShell(), action.getText(), formatMessage("generatecode.warn", getRunStatus()));
83
		} else if (myRunStatus.matches(IStatus.INFO)) {
84
			if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_INFO))) {
85
				MessageDialogWithToggle.openInformation(getShell(), action.getText(), formatMessage("generatecode.info", getRunStatus()), CodegenRcpUiPlugin.getBundleString("generatecode.neveragain"), false, getPreferences(), ASK_INFO);
86
			}
87
		}
88
	}
89
90
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
91
		Generator g = new Generator(getGenModel());
92
		g.run(monitor);
93
		myRunStatus = g.getRunStatus();
94
	}
95
96
	public void selectionChanged(IAction action, ISelection selection) {
97
		mySelection = null;
98
		action.setEnabled(false);
99
		if (selection instanceof IStructuredSelection == false) {
100
			return;
101
		}
102
		mySelection = (IFile) ((IStructuredSelection) selection).getFirstElement();
103
		action.setEnabled(true);
104
	}
105
106
	private static String formatMessage(String bundleStringKey, IStatus status) {
107
		return CodegenRcpUiPlugin.formatMessage(bundleStringKey, status);
108
	}
109
110
	private IStatus getRunStatus() {
111
		return myRunStatus;
112
	}
113
114
	private GenEditorGenerator getGenModel() {
115
		return myGenModel;
116
	}
117
118
	private void loadGenModel() {
119
		URI selected = URI.createPlatformResourceURI(mySelection.getFullPath().toString());
120
		ResourceSet srcResSet = new ResourceSetImpl();
121
// [vano]: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=128998 for a details		
122
		srcResSet.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
123
		Resource srcRes = srcResSet.getResource(selected, true);
124
		Object root = srcRes.getContents().get(0);
125
		if (root instanceof GenDiagram) {
126
			myGenModel = ((GenDiagram) root).getEditorGen();
127
		} else if (root instanceof GenEditorGenerator) {
128
			myGenModel = (GenEditorGenerator) root;
129
		}
130
		if (myGenModel != null && myGenModel.getDomainGenModel() != null) {
131
			myGenModel.getDomainGenModel().reconcile();
132
		}
133
	}
134
135
	private void unloadGenModel() {
136
		if (myGenModel != null && myGenModel.eResource() != null) {
137
			myGenModel.eResource().unload();
138
		}
139
		myGenModel = null;
140
	}
141
142
	private IStatus validateGenModel() {
143
		return BasicDiagnostic.toIStatus(Diagnostician.INSTANCE.validate(getGenModel()));
144
	}
145
146
	private Shell getShell() {
147
		return myPart.getSite().getShell();
148
	}
149
150
	private static IPreferenceStore getPreferences() {
151
		return CodegenRcpUiPlugin.getDefault().getPreferenceStore();
152
	}
153
}
(-)src/org/eclipse/gmf/codegen/lite/ui/CodegenRcpUiPlugin.java (+111 lines)
Added Link Here
1
package org.eclipse.gmf.codegen.lite.ui;
2
3
import java.text.MessageFormat;
4
5
import org.eclipse.ui.plugin.*;
6
import org.eclipse.core.runtime.IStatus;
7
import org.eclipse.core.runtime.Platform;
8
import org.eclipse.core.runtime.Status;
9
import org.eclipse.jface.resource.ImageDescriptor;
10
import org.osgi.framework.BundleContext;
11
12
/**
13
 * The main plugin class to be used in the desktop.
14
 */
15
public class CodegenRcpUiPlugin extends AbstractUIPlugin {
16
17
	//The shared instance.
18
	private static CodegenRcpUiPlugin plugin;
19
	
20
	/**
21
	 * The constructor.
22
	 */
23
	public CodegenRcpUiPlugin() {
24
		plugin = this;
25
	}
26
27
	/**
28
	 * This method is called upon plug-in activation
29
	 */
30
	public void start(BundleContext context) throws Exception {
31
		super.start(context);
32
	}
33
34
	/**
35
	 * This method is called when the plug-in is stopped
36
	 */
37
	public void stop(BundleContext context) throws Exception {
38
		super.stop(context);
39
		plugin = null;
40
	}
41
42
	/**
43
	 * Returns the shared instance.
44
	 *
45
	 * @return the shared instance.
46
	 */
47
	public static CodegenRcpUiPlugin getDefault() {
48
		return plugin;
49
	}
50
51
	/**
52
	 * Returns an image descriptor for the image file at the given
53
	 * plug-in relative path.
54
	 *
55
	 * @param path the path
56
	 * @return the image descriptor
57
	 */
58
	public static ImageDescriptor getImageDescriptor(String path) {
59
		return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.gmf.codegen.lite.ui", path);
60
	}
61
62
	public static String getBundleString(String key) {
63
		return Platform.getResourceBundle(getDefault().getBundle()).getString(key);
64
	}
65
66
	public static String getBundleString(String key, Object[] args) {
67
		String val = getBundleString(key);
68
		if (val == null) {
69
			return key;
70
		}
71
		return MessageFormat.format(val, args);
72
	}
73
74
	public static IStatus createStatus(int statusCode, String message, Exception ex) {
75
		return new Status(statusCode, getPluginID(), 0, message, ex);
76
	}
77
	public static IStatus createError(String message, Exception ex) {
78
		return createStatus(IStatus.ERROR, message, ex);
79
	}
80
	public static IStatus createWarning(String message) {
81
		return createStatus(IStatus.WARNING, message, null);
82
	}
83
	public static IStatus createInfo(String message) {
84
		return createStatus(IStatus.INFO, message, null);
85
	}
86
87
	public static String getPluginID() {
88
		return getDefault().getBundle().getSymbolicName();
89
	}
90
91
	public static String formatMessage(String bundleStringKey, IStatus status) {
92
		if (status.isMultiStatus()) {
93
			IStatus[] children = status.getChildren();
94
			StringBuffer sb = new StringBuffer();
95
			// don't care about too nested statuses just because will switch to
96
			// jobs soon, with
97
			// required support already in place
98
			for (int i = 0; i < children.length && i < 3; i++) {
99
				sb.append(children[i].getMessage());
100
				sb.append('\n');
101
				sb.append('\n');
102
			}
103
			if (children.length >= 3) {
104
				sb.append("...");
105
			}
106
			return getBundleString(bundleStringKey, new Object[] { sb.toString() });
107
		} else {
108
			return getBundleString(bundleStringKey, new Object[] { status.getMessage() });
109
		}
110
	}
111
}
(-)META-INF/MANIFEST.MF (+18 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.gmf.codegen.lite.ui;singleton:=true
5
Bundle-Version: 1.0.0
6
Bundle-Activator: org.eclipse.gmf.codegen.lite.ui.CodegenRcpUiPlugin
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
9
Require-Bundle: org.eclipse.ui,
10
 org.eclipse.core.runtime,
11
 org.eclipse.gmf.codegen.lite,
12
 org.eclipse.core.resources,
13
 org.eclipse.emf.codegen.ecore,
14
 org.eclipse.emf.ecore.xmi,
15
 org.eclipse.emf.ecore.edit,
16
 org.eclipse.emf.ecore.editor,
17
 org.eclipse.gmf.codegen
18
Eclipse-LazyStart: true
(-)plugin.xml (+21 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.popupMenus">
6
      <objectContribution
7
            adaptable="true"
8
            id="gmf.codegen.ui.contribution2"
9
            nameFilter="*.gmfgen"
10
            objectClass="org.eclipse.core.resources.IFile">
11
         <action
12
               label="%generatecode.action"
13
               class="org.eclipse.gmf.internal.codegen.lite.popup.actions.ExecuteTemplatesAction"
14
               menubarPath="additions"
15
               enablesFor="1"
16
               id="gmf.codegen.ui.step2Action">
17
         </action>
18
      </objectContribution>
19
   </extension>
20
21
</plugin>
(-)build.properties (+5 lines)
Added Link Here
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml

Return to bug 136702