Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui')
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/Activator.java70
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/handlers/GenerateJavaCodeHandler.java246
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GeneratorPreferenceImpl.java103
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GenericClassFieldEditor.java69
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PackageListEditor.java87
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceConstants.java41
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceInitializer.java47
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferencePage.java109
8 files changed, 772 insertions, 0 deletions
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/Activator.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/Activator.java
new file mode 100644
index 00000000000..bf812d8fb4e
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/Activator.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.java.generator.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/handlers/GenerateJavaCodeHandler.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/handlers/GenerateJavaCodeHandler.java
new file mode 100644
index 00000000000..5adfd0698df
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/handlers/GenerateJavaCodeHandler.java
@@ -0,0 +1,246 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.java.generator.jdtsynchronizer.RunGenerator;
+import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
+import org.eclipse.papyrus.java.generator.ui.Activator;
+import org.eclipse.papyrus.java.generator.ui.preference.GeneratorPreferenceImpl;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * Handler used to launch Java code generation from a selected UML element.
+ *
+ * @author Cedric dumoulin
+ *
+ */
+public class GenerateJavaCodeHandler extends AbstractHandler implements IHandler {
+
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @param event
+ * @return
+ * @throws ExecutionException
+ *
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ // Get selection
+ // Can't be done in the job.
+ List<Object> objects = lookupSelectedElements();
+ // Execute handler
+ doExecute(objects);
+
+ return null;
+ }
+
+ /**
+ * Get the name used in the {@link RecordingCommand}. This name will be visible in
+ * undo/redo.
+ *
+ * @return The command name to show.
+ */
+ public String getCommandName() {
+ return "Generate Java Code";
+ }
+
+ /**
+ * Return a list of selected domain (UML) elements.
+ *
+ * @return
+ */
+ protected List<NamedElement> getSelectedUmlObject() {
+ List<Object> selections = lookupSelectedElements();
+
+ List<NamedElement> results = new ArrayList<NamedElement>();
+
+ // create model with EList<EObject> objects
+ for (Object obj : selections) {
+ // Adapt object to NamedElement
+ NamedElement ele = null;
+ if (obj instanceof IAdaptable) {
+ ele = (NamedElement) ((IAdaptable) obj).getAdapter(NamedElement.class);
+ }
+ if (ele == null) {
+ ele = (NamedElement) Platform.getAdapterManager().getAdapter(obj, NamedElement.class);
+ }
+
+ // Add uml element if found
+ if (ele != null) {
+ results.add(ele);
+ }
+
+ }
+
+ return results;
+ }
+
+ /**
+ * Do the execution of the command.
+ *
+ * @param objects
+ * List of object to generate Java code from.
+ */
+ protected void doExecute(final List<Object> objects) {
+
+ Job job = new Job("Generate java classes ") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ // execute the task ...
+
+ try {
+ IStatus status = doExecute(monitor, objects);
+ monitor.done();
+ return status;
+ }
+ catch (Exception e) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
+ }
+ finally {
+
+ }
+
+
+ }
+ };
+
+ job.setUser(true);
+ job.schedule();
+
+ }
+
+ /**
+ * Do the execution of the command.
+ *
+ * @param objects
+ * List of object to generate Java code from.
+ */
+ protected IStatus doExecute(IProgressMonitor monitor, List<Object> objects) {
+ monitor.beginTask("Generate ...", 3);
+
+ // create a EList<EObject> who is the model
+ EList<EObject> model = new BasicEList<EObject>();
+
+ // create model with EList<EObject> objects
+ for (Object obj : objects) {
+ // Adapt object to NamedElement
+ NamedElement ele = null;
+ if (obj instanceof IAdaptable) {
+ ele = (NamedElement) ((IAdaptable) obj).getAdapter(NamedElement.class);
+ }
+ if (ele == null) {
+ ele = (NamedElement) Platform.getAdapterManager().getAdapter(obj, NamedElement.class);
+ }
+
+ // Add uml element if found
+ if (ele != null) {
+ model.add(ele);
+ }
+
+ }
+ monitor.worked(1);
+
+ // recover window
+ // IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ // Check if there is a right selection
+ if (model.size() <= 0) {
+ String msg = "No UML element selected. Please select one or more UML element to generate";
+ // MessageDialog.openInformation(window.getShell(),"No Selection", msg);
+
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, msg);
+
+ }
+
+ // error message
+ String message = "";
+
+
+ try {
+ // run code generator
+ RunGenerator runGen = new RunGenerator(model);
+ runGen.runGeneration(new GeneratorPreferenceImpl());
+ } catch (JDTVisitorException e) {
+ // error message
+ StringBuffer stackTrace = new StringBuffer();
+ for (StackTraceElement trace : e.getStackTrace()) {
+ stackTrace.append("at " + trace.getMethodName() + "(" + trace.getClassName() + ":" + trace.getLineNumber() + ")\n");
+ }
+
+ IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
+ // ErrorDialog errDg = new ErrorDialog(window.getShell(), "Error encountered during code generation",
+ // "Error encountered during code generation",
+ // status,
+ // Status.ERROR);
+ // errDg.open();
+ return status;
+ }
+
+ // if(message.isEmpty()) message = "Code generated successfully!";
+
+ monitor.worked(2);
+ // MessageDialog.openInformation(window.getShell(),"Code generation",message);
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Lookup selected objects in UI.
+ *
+ * @return
+ */
+ private List<Object> lookupSelectedElements() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+ // System.out.println("check " + selection);
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ return structuredSelection.toList();
+ }
+ else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection) selection;
+ return treeSelection.toList();
+
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GeneratorPreferenceImpl.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GeneratorPreferenceImpl.java
new file mode 100644
index 00000000000..4b781af05c2
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GeneratorPreferenceImpl.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
+import org.eclipse.papyrus.java.generator.ui.Activator;
+
+public class GeneratorPreferenceImpl implements GeneratorPreference {
+
+ /**
+ * allow to gather default value
+ */
+ private IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+
+ @Override
+ public boolean implementMethodsOfIntefaces() {
+ return store.getBoolean(PreferenceConstants.P_IMPLEMENT_METHODS_OF_INTERFACES_AND_ABSTRACT_CLASS);
+ }
+
+ @Override
+ public boolean implementMethodsOfAbstractClass() {
+ return store.getBoolean(PreferenceConstants.P_IMPLEMENT_METHODS_OF_INTERFACES_AND_ABSTRACT_CLASS);
+ }
+
+ @Override
+ public boolean generateGetters() {
+ return store.getBoolean(PreferenceConstants.P_GENERATE_GETTERS);
+ }
+
+ @Override
+ public boolean generateSetters() {
+ return store.getBoolean(PreferenceConstants.P_GENERATE_SETTERS);
+ }
+
+ @Override
+ public boolean isPackageToGenerate(String packageQualifiedName) {
+ if (packageQualifiedName == null || packageQualifiedName.isEmpty()) {
+ return true;
+ }
+
+ // gather list of packages :
+ String listStr = store.getString(PreferenceConstants.P_FILTER_OF_PACKAGE_NOT_TO_GENERATE);
+
+ // if list of package don't exist, return true
+ if (listStr == null || listStr.isEmpty()) {
+ return true;
+ }
+
+ // gather list in a table
+ String[] listPackage = listStr.split(";");
+
+ for (String _package : listPackage) {
+ if (_package.equals(packageQualifiedName)) {
+ return false;
+ }
+
+ // if package have a *, we delete *
+ String packageWithoutStar = _package;
+ if (_package.contains("*")) {
+ packageWithoutStar = _package.substring(0, _package.indexOf("*") - 1);
+ }
+
+ if (packageQualifiedName.contains(packageWithoutStar)) {
+ return false;
+ }
+ }
+
+ // by default, return true
+ return true;
+ }
+
+ @Override
+ public String genericClassForMultiValue() {
+ return store.getString(PreferenceConstants.P_GENERIC_CLASS_FOR_MULTIVALUE);
+ }
+
+ @Override
+ public boolean stopOnFirstError() {
+ return store.getBoolean(PreferenceConstants.P_STOP_ON_FIRST_ERROR);
+ }
+
+ @Override
+ public String defaultSourceFolderName() {
+ return store.getString(PreferenceConstants.P_DEFAULT_SOURCE_FOLDER_NAME);
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GenericClassFieldEditor.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GenericClassFieldEditor.java
new file mode 100644
index 00000000000..61abda9df3c
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/GenericClassFieldEditor.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.internal.core.BinaryType;
+import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.StringButtonFieldEditor;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * Used to choice a generic class
+ *
+ * @author DEBLOCK Nicolas and GILES Manuel
+ *
+ */
+public class GenericClassFieldEditor extends StringButtonFieldEditor {
+
+ public GenericClassFieldEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ }
+
+ @Override
+ protected String changePressed() {
+
+ // search scope
+ IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
+ FilteredTypesSelectionDialog d = new FilteredTypesSelectionDialog(getShell(), false, null, scope, IJavaSearchConstants.TYPE);
+ d.open();
+ Object[] pack = d.getResult();
+ BinaryType result = (BinaryType) pack[0];
+ try {
+ // if it's not a generic class, generate a error message
+ if (!(result.getClassFile().getType().getFullyQualifiedParameterizedName().contains("<") && result.getClassFile().getType().getFullyQualifiedParameterizedName().contains(">"))) {
+ String errorMessage = "Erreur : " + result.getElementName() + " is not a generic class";
+ MessageDialog.openError(getShell(), "Error", errorMessage);
+ return getStringValue();
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ String errorMessage = "Erreur : " + e.getMessage();
+ MessageDialog.openError(getShell(), "Error", errorMessage);
+ }
+
+
+ return result.getPackageFragment().getElementName() + "." + result.getElementName();
+ }
+
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PackageListEditor.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PackageListEditor.java
new file mode 100644
index 00000000000..20c81ae56e7
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PackageListEditor.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jdt.internal.ui.preferences.TypeFilterInputDialog;
+import org.eclipse.jface.preference.ListEditor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ *
+ * Used to select packages from the dialog.
+ *
+ * @author DEBLOCK Nicolas and GILES Manuel
+ */
+public class PackageListEditor extends ListEditor {
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * @param labelText
+ * @param parent
+ */
+ PackageListEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ }
+
+ @Override
+ /**
+ * Functionality for New button.
+ * Shows a browser dialog to select a file and returns that file.
+ */
+ protected String getNewInputObject() {
+ // Dialog p = new JDialog();
+ List<String> l = new LinkedList<String>();
+
+
+ TypeFilterInputDialog d = new TypeFilterInputDialog(getShell(), l);
+ d.open();
+ Object pack = d.getResult();
+
+ // Return null if user clicked on "cancel" button, to not add ampty package on the list
+ if (d.getReturnCode() == Window.CANCEL) {
+ return null;
+ }
+ return pack.toString();
+ }
+
+ @Override
+ protected String createList(String[] items) {
+ StringBuffer str = new StringBuffer();
+ for (String item : items) {
+ str.append(item + ";");
+ }
+ return str.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * initialize list of items
+ *
+ * @see org.eclipse.jface.preference.ListEditor#parseString(java.lang.String)
+ */
+ @Override
+ protected String[] parseString(String stringList) {
+ return stringList.split(";");
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceConstants.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceConstants.java
new file mode 100644
index 00000000000..674c6f07c68
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceConstants.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+/**
+ * Constant definitions for plug-in preferences
+ */
+public class PreferenceConstants {
+
+ public static final String P_PREFERENCE_ID = "org.eclipse.papyrus.java.generator.ui.preference.PreferencePage";
+
+ public static final String P_IMPLEMENT_METHODS_OF_INTERFACES_AND_ABSTRACT_CLASS = "implementsMethosOfIntefacesAndAbstractClass";
+
+ public static final String P_GENERATE_GETTERS = "generateGetter";
+
+ public static final String P_GENERATE_SETTERS = "generateSetter";
+
+ public static final String P_FILTER_OF_PACKAGE_NOT_TO_GENERATE = "filterOfPackageNotToGenerate";
+
+ public static final String P_GENERIC_CLASS_FOR_MULTIVALUE = "genericClassForMultiValue";
+
+ public static final String P_STOP_ON_FIRST_ERROR = "stopOnFirstError";
+
+ public static final String P_DEFAULT_SOURCE_FOLDER_NAME = "defaultSourceFolderName";
+
+ public static final String LABEL_DEFAULT_SOURCE_FOLDER_NAME = "Default source folder name";
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceInitializer.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceInitializer.java
new file mode 100644
index 00000000000..5bbb763db45
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferenceInitializer.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.java.generator.ui.Activator;
+
+
+/**
+ * Class used to initialize default preference values.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ store.setDefault(PreferenceConstants.P_IMPLEMENT_METHODS_OF_INTERFACES_AND_ABSTRACT_CLASS, true);
+ store.setDefault(PreferenceConstants.P_GENERATE_GETTERS, true);
+ store.setDefault(PreferenceConstants.P_GENERATE_SETTERS, true);
+ store.setDefault(PreferenceConstants.P_FILTER_OF_PACKAGE_NOT_TO_GENERATE, "java.*;javax.*");
+ store.setDefault(PreferenceConstants.P_GENERIC_CLASS_FOR_MULTIVALUE, "java.util.List");
+ store.setDefault(PreferenceConstants.P_STOP_ON_FIRST_ERROR, true);
+ store.setDefault(PreferenceConstants.P_DEFAULT_SOURCE_FOLDER_NAME, "src");
+ }
+
+}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferencePage.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferencePage.java
new file mode 100644
index 00000000000..626d3a8f871
--- /dev/null
+++ b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.ui/src/org/eclipse/papyrus/java/generator/ui/preference/PreferencePage.java
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
+ *
+ *
+ * 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:
+ * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
+ * Manuel Giles giles.manu@live.fr - Initial API and implementation
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.java.generator.ui.preference;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.papyrus.java.generator.ui.Activator;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * This class represents a preference page that
+ * is contributed to the Preferences dialog. By
+ * subclassing <samp>FieldEditorPreferencePage</samp>, we
+ * can use the field support built into JFace that allows
+ * us to create a page that is small and knows how to
+ * save, restore and apply itself.
+ * <p>
+ * This page is used to modify preferences only. They are stored in the preference store that belongs to the main plug-in class. That way, preferences can be accessed directly via the preference store.
+ */
+
+public class PreferencePage
+ extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ public PreferencePage() {
+ super(GRID);
+ }
+
+ /**
+ * Creates the field editors. Field editors are abstractions of
+ * the common GUI blocks needed to manipulate various types
+ * of preferences. Each field editor knows how to save and
+ * restore itself.
+ */
+ @Override
+ public void createFieldEditors() {
+
+ // implements methods of inherits interfaces and abstract class
+ addField(new BooleanFieldEditor(
+ PreferenceConstants.P_STOP_ON_FIRST_ERROR,
+ "Stop on first error",
+ getFieldEditorParent()));
+
+ // implements methods of inherits interfaces and abstract class
+ addField(new BooleanFieldEditor(
+ PreferenceConstants.P_IMPLEMENT_METHODS_OF_INTERFACES_AND_ABSTRACT_CLASS,
+ "Implement methods of inherits interfaces and abstract class",
+ getFieldEditorParent()));
+
+
+ // generate getters setters
+ addField(new BooleanFieldEditor(
+ PreferenceConstants.P_GENERATE_GETTERS,
+ "Generate getters",
+ getFieldEditorParent()));
+
+ addField(new BooleanFieldEditor(
+ PreferenceConstants.P_GENERATE_SETTERS,
+ "Generate setters",
+ getFieldEditorParent()));
+
+ // filter of package not to generate
+ addField(new PackageListEditor(
+ PreferenceConstants.P_FILTER_OF_PACKAGE_NOT_TO_GENERATE,
+ "Filter of package to not generate",
+ getFieldEditorParent()));
+
+ addField(new GenericClassFieldEditor(
+ PreferenceConstants.P_GENERIC_CLASS_FOR_MULTIVALUE,
+ "Generic class to use for association * ",
+ getFieldEditorParent()));
+
+
+ // text input field for the default source folder name
+ addField(new GenericClassFieldEditor(
+ PreferenceConstants.P_DEFAULT_SOURCE_FOLDER_NAME,
+ PreferenceConstants.LABEL_DEFAULT_SOURCE_FOLDER_NAME,
+ getFieldEditorParent()));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("Edit your preferences to generate Java classes with papyrus");
+ }
+
+
+
+}

Back to the top