Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink')
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/Activator.java78
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/Messages.java55
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/messages.properties53
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/BasicDatabasePreferencePage.java138
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/IDatabasePreferenceConstants.java31
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/AbstractLoadModelFromDatabaseWizard.java90
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/AbstractRootObjectAndModelEditorPage.java265
-rwxr-xr-xeclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/BasicModelAndDatabaseAccessParametersPage.java453
8 files changed, 1163 insertions, 0 deletions
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/Activator.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/Activator.java
new file mode 100755
index 000000000..5cf98ad7d
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/Activator.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui;
+
+import org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages.IDatabasePreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+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.emf.teneo.eclipselink.common.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * (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;
+ }
+
+ /**
+ * Returns the database settings which will show up when Preference dialog opens up for the first time.
+ */
+ @Override
+ protected void initializeDefaultPreferences(IPreferenceStore store) {
+ store.setDefault(IDatabasePreferenceConstants.USE_LOGIN_FROM,
+ IDatabasePreferenceConstants.USE_LOGIN_FROM_DEFAULT);
+ store.setDefault(IDatabasePreferenceConstants.DATABASE_URL, IDatabasePreferenceConstants.DATABASE_URL_DEFAULT);
+ store.setDefault(IDatabasePreferenceConstants.JDBC_DRIVER, IDatabasePreferenceConstants.JDBC_DRIVER_DEFAULT);
+ store.setDefault(IDatabasePreferenceConstants.USER_NAME, IDatabasePreferenceConstants.USER_NAME_DEFAULT);
+ store.setDefault(IDatabasePreferenceConstants.PASSWORD, IDatabasePreferenceConstants.PASSWORD_DEFAULT);
+ }
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/Messages.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/Messages.java
new file mode 100755
index 000000000..12485709f
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/Messages.java
@@ -0,0 +1,55 @@
+package org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages.messages"; //$NON-NLS-1$
+ public static String button_fromPersistenceUnit;
+ public static String button_fromUserPreferences;
+ public static String error_databaseContainsNo$0Objects;
+ public static String error_databaseURLMissing;
+ public static String error_editorIDMissing;
+ public static String error_editorIDMustIdentifyExistingEditor;
+ public static String error_failedToOpenDatabase;
+ public static String error_jdbcDriverMissing;
+ public static String error_packageNamespaceURIMissing;
+ public static String error_packageNamespaceURIMustIdentifyExistingEcorePackage;
+ public static String error_passwordMissing;
+ public static String error_persistenceUnitNameMissing;
+ public static String error_persistenceUnitNameMustIdentifyExistingPersistenceUnit;
+ public static String error_rootObjectMissing;
+ public static String error_rootObjectMustBeExistingRootObjectCandidate;
+ public static String error_rootObjectMustBeInEcorePackage$0;
+ public static String error_rootObjectTypeMissing;
+ public static String error_userNameMissing;
+ public static String group_databaseLogin;
+ public static String label_DatabaseURL;
+ public static String label_editorID;
+ public static String label_jdbcDriver;
+ public static String label_packageNamespaceURI;
+ public static String label_password;
+ public static String label_persistenceUnitName;
+ public static String label_rootObject;
+ public static String label_rootObjectType;
+ public static String label_userName;
+ public static String message_loadsModelFromDatabaseUsingURI$0;
+ public static String page_emfModelAndDatabase_description;
+ public static String page_emfModelAndDatabase_title;
+ public static String page_rootObjectAndEMFModelEditor_description;
+ public static String page_rootObjectAndEMFModelEditor_title;
+ public static String value_databaseLogin;
+ public static String value_databaseURL;
+ public static String value_fromPersistenceUnit;
+ public static String value_fromUserPreferences;
+ public static String value_jdbcDriver;
+ public static String value_password;
+ public static String value_userName;
+ public static String wizard_loadEMFModelFromDatabase_title;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/messages.properties b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/messages.properties
new file mode 100755
index 000000000..2563550cb
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/internal/messages/messages.properties
@@ -0,0 +1,53 @@
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+button_fromPersistenceUnit=from Persistence Unit
+button_fromUserPreferences=from user preferences
+error_databaseContainsNo$0Objects=Database contains no "{0}" objects. Go back and select another EMF model package and/or root object type.
+error_databaseURLMissing=Database URL name must be specified.
+error_editorIDMissing=Editor ID must be specified.
+error_editorIDMustIdentifyExistingEditor=Editor ID must identify existing database-enabled editor.
+error_failedToOpenDatabase=Failed to open database. Go back and make sure that model and database access parameters are correct. See Error Log for details if this problem still occurs.
+error_jdbcDriverMissing=JDBC driver must be specified.
+error_packageNamespaceURIMissing=Package namespace URI must be specified.
+error_packageNamespaceURIMustIdentifyExistingEcorePackage=Package namespace URI must identify existing Ecore package registred in global Ecore package registry.
+error_passwordMissing=Password must be specified.
+error_persistenceUnitNameMissing=Persistence Unit name must be specified.
+error_persistenceUnitNameMustIdentifyExistingPersistenceUnit=Persistence Unit name must identify existing Persistence Unit.
+error_rootObjectMissing=Root object must be specified.
+error_rootObjectMustBeExistingRootObjectCandidate=Root object must be member of existing root object candidates.
+error_rootObjectMustBeInEcorePackage$0=Root object type must be member of Ecore package "{0}".
+error_rootObjectTypeMissing=Root object type must be specified.
+error_userNameMissing=User name must be specified.
+group_databaseLogin=Database login:
+label_DatabaseURL=Database URL:
+label_editorID=Editor ID:
+label_jdbcDriver=JDBC driver:
+label_packageNamespaceURI=Package namespace URI:
+label_password=Password:
+label_persistenceUnitName=Persistence Unit name:
+label_rootObject=Root object:
+label_rootObjectType=Root object type:
+label_userName=User name:
+message_loadsModelFromDatabaseUsingURI$0=Loads model from database using following URI:\n{0}
+page_emfModelAndDatabase_description=Set access parameters for EMF model and database.
+page_emfModelAndDatabase_title=EMF Model and Database
+page_rootObjectAndEMFModelEditor_description=Select root object and database-enabled EMF model editor.
+page_rootObjectAndEMFModelEditor_title=Root Object and EMF Model Editor
+value_databaseLogin=Database login:
+value_databaseURL=Database URL:
+value_fromPersistenceUnit=from Persistence Unit
+value_fromUserPreferences=from user preferences
+value_jdbcDriver=JDBC driver:
+value_password=Password:
+value_userName=User name:
+wizard_loadEMFModelFromDatabase_title=Load EMF Model from Database
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/BasicDatabasePreferencePage.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/BasicDatabasePreferencePage.java
new file mode 100755
index 000000000..9cb90046b
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/BasicDatabasePreferencePage.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages;
+
+import org.eclipse.emf.teneo.eclipselink.common.ui.Activator;
+import org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages.Messages;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class BasicDatabasePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ protected RadioGroupFieldEditor useLoginFromEditor;
+ protected Composite useLoginFromEditorComposite;
+
+ protected StringFieldEditor databaseURLEditor;
+ protected StringFieldEditor jdbcDriverEditor;
+ protected StringFieldEditor userNameEditor;
+ protected StringFieldEditor passwordEditor;
+
+ public BasicDatabasePreferencePage() {
+ super("", GRID); //$NON-NLS-1$
+ }
+
+ public BasicDatabasePreferencePage(String title) {
+ super(title, GRID);
+ }
+
+ public BasicDatabasePreferencePage(String title, ImageDescriptor image) {
+ super(title, image, GRID);
+ }
+
+ public void init(IWorkbench workbench) {
+
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ // create use login from selection widgets
+ useLoginFromEditor = new RadioGroupFieldEditor(IDatabasePreferenceConstants.USE_LOGIN_FROM,
+ Messages.value_databaseLogin, 1, new String[][] {
+ { Messages.value_fromPersistenceUnit,
+ IDatabasePreferenceConstants.USE_LOGIN_FROM_PERSISTENCE_UNIT },
+ { Messages.value_fromUserPreferences,
+ IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES } },
+ getFieldEditorParent(), true);
+ addField(useLoginFromEditor);
+ useLoginFromEditorComposite = useLoginFromEditor.getRadioBoxControl(getFieldEditorParent());
+
+ // create database URL selection widgets
+ databaseURLEditor = new StringFieldEditor(IDatabasePreferenceConstants.DATABASE_URL,
+ Messages.value_databaseURL, useLoginFromEditorComposite);
+ databaseURLEditor.setEnabled(false, useLoginFromEditorComposite);
+ addField(databaseURLEditor);
+
+ // create JDBC driver selection widgets
+ jdbcDriverEditor = new StringFieldEditor(IDatabasePreferenceConstants.JDBC_DRIVER, Messages.value_jdbcDriver,
+ useLoginFromEditorComposite);
+ addField(jdbcDriverEditor);
+
+ // create user name widgets
+ userNameEditor = new StringFieldEditor(IDatabasePreferenceConstants.USER_NAME, Messages.value_userName,
+ useLoginFromEditorComposite);
+ addField(userNameEditor);
+
+ // create password name widgets
+ passwordEditor = new StringFieldEditor(IDatabasePreferenceConstants.PASSWORD, Messages.value_password,
+ useLoginFromEditorComposite);
+ Text passwordField = passwordEditor.getTextControl(useLoginFromEditorComposite);
+ passwordField.setEchoChar('*');
+ addField(passwordEditor);
+
+ // adjust layout of use login from selection widgets
+ GridLayout layout = (GridLayout) useLoginFromEditorComposite.getLayout();
+ layout.marginWidth = 5;
+ layout.marginHeight = 5;
+
+ // set the field editors's enabled state
+ IPreferenceStore store = getPreferenceStore();
+ setFieldEditorsEnabled(store.getString(IDatabasePreferenceConstants.USE_LOGIN_FROM));
+ }
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ super.propertyChange(event);
+ // event originating from use login from selection widgets?
+ if (event.getSource() == useLoginFromEditor) {
+ // set the field editors's enabled state
+ setFieldEditorsEnabled((String) event.getNewValue());
+ }
+ }
+
+ protected void setFieldEditorsEnabled(String useLoginFromValue) {
+ if (IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES.equals(useLoginFromValue)) {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ databaseURLEditor.setStringValue(store.getString(IDatabasePreferenceConstants.DATABASE_URL));
+ jdbcDriverEditor.setStringValue(store.getString(IDatabasePreferenceConstants.JDBC_DRIVER));
+ userNameEditor.setStringValue(store.getString(IDatabasePreferenceConstants.USER_NAME));
+ passwordEditor.setStringValue(store.getString(IDatabasePreferenceConstants.PASSWORD));
+
+ databaseURLEditor.setEnabled(true, useLoginFromEditorComposite);
+ jdbcDriverEditor.setEnabled(true, useLoginFromEditorComposite);
+ userNameEditor.setEnabled(true, useLoginFromEditorComposite);
+ passwordEditor.setEnabled(true, useLoginFromEditorComposite);
+ } else {
+ databaseURLEditor.setStringValue(null);
+ jdbcDriverEditor.setStringValue(null);
+ userNameEditor.setStringValue(null);
+ passwordEditor.setStringValue(null);
+
+ databaseURLEditor.setEnabled(false, useLoginFromEditorComposite);
+ jdbcDriverEditor.setEnabled(false, useLoginFromEditorComposite);
+ userNameEditor.setEnabled(false, useLoginFromEditorComposite);
+ passwordEditor.setEnabled(false, useLoginFromEditorComposite);
+ }
+ }
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/IDatabasePreferenceConstants.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/IDatabasePreferenceConstants.java
new file mode 100755
index 000000000..08e7d7da5
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/preferencepages/IDatabasePreferenceConstants.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages;
+
+public interface IDatabasePreferenceConstants {
+
+ String USE_LOGIN_FROM = "USE_LOGIN_FROM"; //$NON-NLS-1$
+ String USE_LOGIN_FROM_PERSISTENCE_UNIT = "from_persistence_unit"; //$NON-NLS-1$
+ String USE_LOGIN_FROM_USER_PREFERENCES = "from_user_preferences"; //$NON-NLS-1$
+ String USE_LOGIN_FROM_DEFAULT = USE_LOGIN_FROM_PERSISTENCE_UNIT;
+
+ String DATABASE_URL = "DATABASE_URL"; //$NON-NLS-1$
+ String DATABASE_URL_DEFAULT = "jdbc:derby://localhost:1527/sample;create=true"; //$NON-NLS-1$
+
+ String JDBC_DRIVER = "JDBC_DRIVER"; //$NON-NLS-1$
+ String JDBC_DRIVER_DEFAULT = "org.apache.derby.jdbc.ClientDriver"; //$NON-NLS-1$
+
+ String USER_NAME = "USER_NAME"; //$NON-NLS-1$
+ String USER_NAME_DEFAULT = ""; //$NON-NLS-1$
+
+ String PASSWORD = "PASSWORD"; //$NON-NLS-1$
+ String PASSWORD_DEFAULT = ""; //$NON-NLS-1$
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/AbstractLoadModelFromDatabaseWizard.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/AbstractLoadModelFromDatabaseWizard.java
new file mode 100755
index 000000000..aed743db4
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/AbstractLoadModelFromDatabaseWizard.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui.wizards;
+
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.teneo.eclipselink.common.ui.Activator;
+import org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages.Messages;
+import org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages.IDatabasePreferenceConstants;
+import org.eclipse.emf.teneo.eclipselink.common.ui.wizards.pages.AbstractRootObjectAndModelEditorPage;
+import org.eclipse.emf.teneo.eclipselink.common.ui.wizards.pages.BasicModelAndDatabaseAccessParametersPage;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+public abstract class AbstractLoadModelFromDatabaseWizard extends Wizard {
+
+ protected BasicModelAndDatabaseAccessParametersPage modelAndDatabaseAccessParametersPage;
+ protected AbstractRootObjectAndModelEditorPage rootObjectAndModelEditorPage;
+
+ public AbstractLoadModelFromDatabaseWizard() {
+ setWindowTitle(Messages.wizard_loadEMFModelFromDatabase_title);
+ }
+
+ @Override
+ public void addPages() {
+ modelAndDatabaseAccessParametersPage = createModelAndDatabaseAccessParametersPage("Page1"); //$NON-NLS-1$
+ modelAndDatabaseAccessParametersPage.setTitle(Messages.page_emfModelAndDatabase_title);
+ modelAndDatabaseAccessParametersPage.setDescription(Messages.page_emfModelAndDatabase_description);
+ addPage(modelAndDatabaseAccessParametersPage);
+
+ rootObjectAndModelEditorPage = createRootObjectAndModelEditorPage("Page2"); //$NON-NLS-1$
+ rootObjectAndModelEditorPage.setTitle(Messages.page_rootObjectAndEMFModelEditor_title);
+ rootObjectAndModelEditorPage.setDescription(Messages.page_rootObjectAndEMFModelEditor_description);
+ addPage(rootObjectAndModelEditorPage);
+ }
+
+ @Override
+ public boolean performFinish() {
+ // update database settings in user preferences as far as required
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ store.setValue(IDatabasePreferenceConstants.USE_LOGIN_FROM, modelAndDatabaseAccessParametersPage
+ .getUseLoginFrom());
+ if (IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES.equals(modelAndDatabaseAccessParametersPage
+ .getUseLoginFrom())) {
+ store.setValue(IDatabasePreferenceConstants.DATABASE_URL, modelAndDatabaseAccessParametersPage
+ .getDatabaseURL());
+ store.setValue(IDatabasePreferenceConstants.JDBC_DRIVER, modelAndDatabaseAccessParametersPage
+ .getJDBCDriver());
+ store.setValue(IDatabasePreferenceConstants.USER_NAME, modelAndDatabaseAccessParametersPage.getUserName());
+ store.setValue(IDatabasePreferenceConstants.PASSWORD, modelAndDatabaseAccessParametersPage.getPassword());
+ }
+
+ // create database URI for selected root object
+ URI uri = createDatabaseURI(modelAndDatabaseAccessParametersPage.getPersistenceUnitName(),
+ rootObjectAndModelEditorPage.getRootObject());
+
+ // open editor on new database URI
+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchPage page = workbenchWindow.getActivePage();
+ try {
+ page.openEditor(new URIEditorInput(uri), rootObjectAndModelEditorPage.getEditorId());
+ } catch (PartInitException piex) {
+ MessageDialog.openError(workbenchWindow.getShell(), getWindowTitle(), piex.getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+ protected abstract BasicModelAndDatabaseAccessParametersPage createModelAndDatabaseAccessParametersPage(
+ String pageName);
+
+ protected abstract AbstractRootObjectAndModelEditorPage createRootObjectAndModelEditorPage(String pageName);
+
+ protected abstract URI createDatabaseURI(String persistenceUnitName, EObject rootObject);
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/AbstractRootObjectAndModelEditorPage.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/AbstractRootObjectAndModelEditorPage.java
new file mode 100755
index 000000000..df29a23f5
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/AbstractRootObjectAndModelEditorPage.java
@@ -0,0 +1,265 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui.wizards.pages;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.teneo.eclipselink.common.ui.Activator;
+import org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages.Messages;
+import org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages.IDatabasePreferenceConstants;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+public abstract class AbstractRootObjectAndModelEditorPage extends WizardPage {
+
+ protected static QualifiedName rootObjectName = new QualifiedName(Activator.getDefault().getBundle()
+ .getSymbolicName(), "rootObject"); //$NON-NLS-1$
+ protected static QualifiedName editorIdName = new QualifiedName(Activator.getDefault().getBundle()
+ .getSymbolicName(), "editorId"); //$NON-NLS-1$
+
+ protected Combo rootObjectField;
+ protected Combo editorIdField;
+
+ protected AdapterFactoryItemDelegator adapterFactoryItemDelegator;
+ protected List<EObject> rootObjectCandidates = new ArrayList<EObject>();
+
+ public AbstractRootObjectAndModelEditorPage(String pageName) {
+ super(pageName);
+ AdapterFactory adapterFactory = new ReflectiveItemProviderAdapterFactory();
+ adapterFactoryItemDelegator = new AdapterFactoryItemDelegator(adapterFactory);
+ }
+
+ public EObject getRootObject() {
+ EObject result = null;
+ for (EObject eObject : rootObjectCandidates) {
+ String name = adapterFactoryItemDelegator.getText(eObject);
+ if (name.equals(rootObjectField.getText())) {
+ result = eObject;
+ }
+ }
+ return result;
+ }
+
+ public String getEditorId() {
+ return editorIdField.getText();
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ new Label(composite, SWT.LEFT).setText(Messages.label_rootObject);
+
+ rootObjectField = new Combo(composite, SWT.BORDER);
+ rootObjectField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ rootObjectField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+
+ EObject rootObject = getRootObject();
+ if (rootObject != null) {
+ URI uri = createDatabaseURI(getTypedPreviousPage().getPersistenceUnitName(), rootObject);
+ setMessage(NLS.bind(Messages.message_loadsModelFromDatabaseUsingURI$0, uri));
+ }
+ }
+ });
+
+ new Label(composite, SWT.LEFT).setText(Messages.label_editorID);
+
+ editorIdField = new Combo(composite, SWT.BORDER);
+ editorIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initEditorIdField();
+ editorIdField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ setPageComplete(validatePage());
+ setControl(composite);
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ updateRootObjectField();
+ } else {
+ persistWidgets();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ persistWidgets();
+ super.dispose();
+ }
+
+ protected void initEditorIdField() {
+ for (String editorId : getEditorIds()) {
+ editorIdField.add(editorId);
+ }
+ int index = 0;
+ try {
+ String lastEditorId = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(editorIdName);
+ index = Arrays.asList(editorIdField.getItems()).indexOf(lastEditorId);
+ index = index != -1 ? index : 0;
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ editorIdField.select(index);
+ }
+
+ protected void updateRootObjectField() {
+ rootObjectField.removeAll();
+
+ rootObjectCandidates = loadRootObjectCandidates();
+ for (EObject eObject : rootObjectCandidates) {
+ String label = adapterFactoryItemDelegator.getText(eObject);
+ rootObjectField.add(label);
+ }
+ int index = 0;
+ try {
+ String lastRootObject = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(rootObjectName);
+ index = Arrays.asList(rootObjectField.getItems()).indexOf(lastRootObject);
+ index = index != -1 ? index : 0;
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ rootObjectField.select(index);
+ }
+
+ protected boolean validatePage() {
+ setErrorMessage(null);
+ if (isBlank(rootObjectField.getText())) {
+ setErrorMessage(Messages.error_rootObjectMissing);
+ return false;
+ }
+ if (!Arrays.asList(rootObjectField.getItems()).contains(rootObjectField.getText())) {
+ setErrorMessage(Messages.error_rootObjectMustBeExistingRootObjectCandidate);
+ return false;
+ }
+ if (isBlank(editorIdField.getText())) {
+ setErrorMessage(Messages.error_editorIDMissing);
+ return false;
+ }
+ if (!Arrays.asList(editorIdField.getItems()).contains(editorIdField.getText())) {
+ setErrorMessage(Messages.error_editorIDMustIdentifyExistingEditor);
+ return false;
+ }
+ return true;
+ }
+
+ protected void persistWidgets() {
+ try {
+ ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(rootObjectName, rootObjectField.getText());
+ ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(editorIdName, editorIdField.getText());
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ }
+
+ protected abstract URI createDatabaseURI(String persistenceUnitName, EClass eClass);
+
+ protected abstract URI createDatabaseURI(String persistenceUnitName, EObject eObject);
+
+ protected abstract Map<String, Object> getPersistenceUnitProperties();
+
+ protected abstract Map<String, Object> getDatabaseLoginOptionsFromPreviousPage();
+
+ protected boolean isBlank(String string) {
+ return string == null || string.trim().length() == 0;
+ }
+
+ protected BasicModelAndDatabaseAccessParametersPage getTypedPreviousPage() {
+ return (BasicModelAndDatabaseAccessParametersPage) getPreviousPage();
+ }
+
+ protected List<EObject> loadRootObjectCandidates() {
+ List<EObject> result = new ArrayList<EObject>();
+ EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(getTypedPreviousPage().getPackageNsURI());
+ EClass eRootClass = (EClass) ePackage.getEClassifier(getTypedPreviousPage().getRootObjectTypeName());
+ URI uri = createDatabaseURI(getTypedPreviousPage().getPersistenceUnitName(), eRootClass);
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getLoadOptions().putAll(getPersistenceUnitProperties());
+ if (IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES.equals(getTypedPreviousPage()
+ .getUseLoginFrom())) {
+ resourceSet.getLoadOptions().putAll(getDatabaseLoginOptionsFromPreviousPage());
+ }
+ Resource resource = null;
+ try {
+ resource = resourceSet.getResource(uri, true);
+ EList<EObject> contents = resource.getContents();
+ if (contents.size() > 0) {
+ result.addAll(contents);
+ } else {
+ setErrorMessage(NLS.bind(Messages.error_databaseContainsNo$0Objects, eRootClass.getName()));
+ }
+ } catch (Exception exception) {
+ setErrorMessage(Messages.error_failedToOpenDatabase);
+ Activator.getDefault().getLog().log(
+ new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getMessage(), exception));
+ } finally {
+ if (resource != null) {
+ resource.unload();
+ }
+ }
+
+ return result;
+ }
+
+ protected List<String> getEditorIds() {
+ List<String> result = new ArrayList<String>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.ui.editors"); //$NON-NLS-1$
+ if (elements != null) {
+ for (IConfigurationElement element : elements) {
+ String extensions = element.getAttribute("extensions"); //$NON-NLS-1$
+ if (extensions != null && extensions.indexOf("database") != -1) { //$NON-NLS-1$
+ result.add(element.getAttribute("id")); //$NON-NLS-1$
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/BasicModelAndDatabaseAccessParametersPage.java b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/BasicModelAndDatabaseAccessParametersPage.java
new file mode 100755
index 000000000..07add6064
--- /dev/null
+++ b/eclipselink/org.eclipse.emf.teneo.eclipselink.common.ui/src/org/eclipse/emf/teneo/eclipselink/common/ui/wizards/pages/BasicModelAndDatabaseAccessParametersPage.java
@@ -0,0 +1,453 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * 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:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.common.ui.wizards.pages;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.eclipselink.common.ui.Activator;
+import org.eclipse.emf.teneo.eclipselink.common.ui.internal.messages.Messages;
+import org.eclipse.emf.teneo.eclipselink.common.ui.preferencepages.IDatabasePreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class BasicModelAndDatabaseAccessParametersPage extends WizardPage {
+
+ protected static QualifiedName packageNsURIName = new QualifiedName(Activator.getDefault().getBundle()
+ .getSymbolicName(), "packageNsURI"); //$NON-NLS-1$
+ protected static QualifiedName rootObjectTypeName = new QualifiedName(Activator.getDefault().getBundle()
+ .getSymbolicName(), "rootObjectType"); //$NON-NLS-1$
+ protected static QualifiedName persistenceUnitNameName = new QualifiedName(Activator.getDefault().getBundle()
+ .getSymbolicName(), "persistenceUnitName"); //$NON-NLS-1$
+
+ protected Combo packageNsURIField;
+ protected Combo rootObjectTypeField;
+ protected Combo persistenceUnitNameField;
+
+ protected Button useLoginFromPersistenceUnitButton;
+ protected Button useLoginFromUserPreferencesButton;
+ private Label databaseURLLabel;
+ protected Combo databaseURLField;
+ private Label jdbcDriverLabel;
+ protected Combo jdbcDriverField;
+ private Label userNameLabel;
+ protected Text userNameField;
+ private Label passwordLabel;
+ protected Text passwordField;
+
+ public BasicModelAndDatabaseAccessParametersPage(String pageName) {
+ super(pageName);
+ }
+
+ public String getPackageNsURI() {
+ return packageNsURIField.getText();
+ }
+
+ public String getRootObjectTypeName() {
+ return rootObjectTypeField.getText();
+ }
+
+ public String getPersistenceUnitName() {
+ return persistenceUnitNameField.getText();
+ }
+
+ public String getUseLoginFrom() {
+ String result;
+ if (useLoginFromUserPreferencesButton.getSelection()) {
+ result = IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES;
+ } else {
+ result = IDatabasePreferenceConstants.USE_LOGIN_FROM_PERSISTENCE_UNIT;
+ }
+ return result;
+ }
+
+ public String getDatabaseURL() {
+ return databaseURLField.getText();
+ }
+
+ public String getJDBCDriver() {
+ return jdbcDriverField.getText();
+ }
+
+ public String getUserName() {
+ return userNameField.getText();
+ }
+
+ public String getPassword() {
+ return passwordField.getText();
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ createModelAndPersistenceUnitGroup(composite);
+ createDatabaseLoginGroup(composite);
+
+ setPageComplete(validatePage());
+ setControl(composite);
+ }
+
+ private void createModelAndPersistenceUnitGroup(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // create Ecore package namespace URI selection widgets
+ new Label(composite, SWT.LEFT).setText(Messages.label_packageNamespaceURI);
+
+ packageNsURIField = new Combo(composite, SWT.BORDER);
+ packageNsURIField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initPackageNsURIField();
+ packageNsURIField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateRootObjectTypeField();
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create root object type selection widgets
+ new Label(composite, SWT.LEFT).setText(Messages.label_rootObjectType);
+
+ rootObjectTypeField = new Combo(composite, SWT.BORDER);
+ rootObjectTypeField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ rootObjectTypeField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create persistence unit name selection widgets
+ new Label(composite, SWT.LEFT).setText(Messages.label_persistenceUnitName);
+
+ persistenceUnitNameField = new Combo(composite, SWT.BORDER);
+ persistenceUnitNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initPersistenceUnitNameField();
+ persistenceUnitNameField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ updateRootObjectTypeField();
+ }
+
+ private void createDatabaseLoginGroup(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText(Messages.group_databaseLogin);
+ group.setLayout(new GridLayout(2, false));
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // create use login from selection widgets
+ useLoginFromPersistenceUnitButton = new Button(group, SWT.RADIO);
+ useLoginFromPersistenceUnitButton.setText(Messages.button_fromPersistenceUnit);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 2;
+ useLoginFromPersistenceUnitButton.setLayoutData(gridData);
+ useLoginFromUserPreferencesButton = new Button(group, SWT.RADIO);
+ useLoginFromUserPreferencesButton.setText(Messages.button_fromUserPreferences);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 2;
+ useLoginFromUserPreferencesButton.setLayoutData(gridData);
+ initUseLoginFromButtons();
+ useLoginFromUserPreferencesButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ updateDatabaseLoginFields();
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create database URL selection widgets
+ databaseURLLabel = new Label(group, SWT.LEFT);
+ databaseURLLabel.setText(Messages.label_DatabaseURL);
+
+ databaseURLField = new Combo(group, SWT.BORDER);
+ databaseURLField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initDatabaseURLField();
+ databaseURLField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create JDBC driver selection widgets
+ jdbcDriverLabel = new Label(group, SWT.LEFT);
+ jdbcDriverLabel.setText(Messages.label_jdbcDriver);
+
+ jdbcDriverField = new Combo(group, SWT.BORDER);
+ jdbcDriverField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initJDBCDriverField();
+ jdbcDriverField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create user name widgets
+ userNameLabel = new Label(group, SWT.LEFT);
+ userNameLabel.setText(Messages.label_userName);
+
+ userNameField = new Text(group, SWT.BORDER);
+ userNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ userNameField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ // create password name widgets
+ passwordLabel = new Label(group, SWT.LEFT);
+ passwordLabel.setText(Messages.label_password);
+
+ passwordField = new Text(group, SWT.BORDER);
+ passwordField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ passwordField.setEchoChar('*');
+ passwordField.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ setPageComplete(validatePage());
+ }
+ });
+
+ updateDatabaseLoginFields();
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (!visible) {
+ persistWidgets();
+ }
+ }
+
+ protected void initPackageNsURIField() {
+ for (String nsURI : getModelNsURIs()) {
+ packageNsURIField.add(nsURI);
+ }
+ int index = 0;
+ try {
+ String lastPackageNsURI = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(packageNsURIName);
+ index = Arrays.asList(packageNsURIField.getItems()).indexOf(lastPackageNsURI);
+ index = index != -1 ? index : 0;
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ packageNsURIField.select(index);
+ }
+
+ protected void initPersistenceUnitNameField() {
+ for (String name : getPersistenceUnitNames()) {
+ persistenceUnitNameField.add(name);
+ }
+ int index = 0;
+ try {
+ String lastPersistenceUnitName = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(
+ persistenceUnitNameName);
+ index = Arrays.asList(persistenceUnitNameField.getItems()).indexOf(lastPersistenceUnitName);
+ index = index != -1 ? index : 0;
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ persistenceUnitNameField.select(index);
+ }
+
+ protected void initUseLoginFromButtons() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ String useLoginFrom = store.getString(IDatabasePreferenceConstants.USE_LOGIN_FROM);
+ useLoginFromPersistenceUnitButton.setSelection(IDatabasePreferenceConstants.USE_LOGIN_FROM_PERSISTENCE_UNIT
+ .equals(useLoginFrom));
+ useLoginFromUserPreferencesButton.setSelection(IDatabasePreferenceConstants.USE_LOGIN_FROM_USER_PREFERENCES
+ .equals(useLoginFrom));
+ }
+
+ protected void initDatabaseURLField() {
+ databaseURLField.add("jdbc:derby://localhost:1527/sample;create=true"); //$NON-NLS-1$
+ databaseURLField.add("jdbc:oracle:thin:@localhost:1521:XE"); //$NON-NLS-1$
+ databaseURLField.add("jdbc:oracle:thin:@localhost:1521:ORCL"); //$NON-NLS-1$
+ }
+
+ protected void initJDBCDriverField() {
+ jdbcDriverField.add("org.apache.derby.jdbc.ClientDriver"); //$NON-NLS-1$
+ jdbcDriverField.add("oracle.jdbc.OracleDriver"); //$NON-NLS-1$
+ jdbcDriverField.add("com.mysql.jdbc.Driver"); //$NON-NLS-1$
+ }
+
+ protected void updateRootObjectTypeField() {
+ rootObjectTypeField.removeAll();
+
+ for (String name : getModelObjectTypeNames(packageNsURIField.getText())) {
+ rootObjectTypeField.add(name);
+ }
+ int index = 0;
+ try {
+ String lastRootObjectType = ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(
+ rootObjectTypeName);
+ index = Arrays.asList(rootObjectTypeField.getItems()).indexOf(lastRootObjectType);
+ index = index != -1 ? index : 0;
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ rootObjectTypeField.select(index);
+ }
+
+ protected void updateDatabaseLoginFields() {
+
+ if (useLoginFromUserPreferencesButton.getSelection()) {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ databaseURLField.setText(store.getString(IDatabasePreferenceConstants.DATABASE_URL));
+ jdbcDriverField.setText(store.getString(IDatabasePreferenceConstants.JDBC_DRIVER));
+ userNameField.setText(store.getString(IDatabasePreferenceConstants.USER_NAME));
+ passwordField.setText(store.getString(IDatabasePreferenceConstants.PASSWORD));
+
+ databaseURLLabel.setEnabled(true);
+ databaseURLField.setEnabled(true);
+ jdbcDriverLabel.setEnabled(true);
+ jdbcDriverField.setEnabled(true);
+ userNameLabel.setEnabled(true);
+ userNameField.setEnabled(true);
+ passwordLabel.setEnabled(true);
+ passwordField.setEnabled(true);
+ } else {
+ updateDatabaseLoginFieldsFromPersistenceUnit();
+
+ databaseURLLabel.setEnabled(false);
+ databaseURLField.setEnabled(false);
+ jdbcDriverLabel.setEnabled(false);
+ jdbcDriverField.setEnabled(false);
+ userNameLabel.setEnabled(false);
+ userNameField.setEnabled(false);
+ passwordLabel.setEnabled(false);
+ passwordField.setEnabled(false);
+ }
+ }
+
+ protected boolean validatePage() {
+ setErrorMessage(null);
+ if (isBlank(packageNsURIField.getText())) {
+ setErrorMessage(Messages.error_packageNamespaceURIMissing);
+ return false;
+ }
+ if (!Arrays.asList(packageNsURIField.getItems()).contains(packageNsURIField.getText())) {
+ setErrorMessage(Messages.error_packageNamespaceURIMustIdentifyExistingEcorePackage);
+ return false;
+ }
+ if (isBlank(rootObjectTypeField.getText())) {
+ setErrorMessage(Messages.error_rootObjectTypeMissing);
+ return false;
+ }
+ if (!Arrays.asList(rootObjectTypeField.getItems()).contains(rootObjectTypeField.getText())) {
+ setErrorMessage(NLS.bind(Messages.error_rootObjectMustBeInEcorePackage$0, packageNsURIField.getText()));
+ return false;
+ }
+ if (isBlank(persistenceUnitNameField.getText())) {
+ setErrorMessage(Messages.error_persistenceUnitNameMissing);
+ return false;
+ }
+ if (!Arrays.asList(persistenceUnitNameField.getItems()).contains(persistenceUnitNameField.getText())) {
+ setErrorMessage(Messages.error_persistenceUnitNameMustIdentifyExistingPersistenceUnit);
+ return false;
+ }
+ if (useLoginFromUserPreferencesButton != null && useLoginFromUserPreferencesButton.getSelection()) {
+ if (isBlank(databaseURLField.getText())) {
+ setErrorMessage(Messages.error_databaseURLMissing);
+ return false;
+ }
+ if (isBlank(jdbcDriverField.getText())) {
+ setErrorMessage(Messages.error_jdbcDriverMissing);
+ return false;
+ }
+ if (isBlank(userNameField.getText())) {
+ setErrorMessage(Messages.error_userNameMissing);
+ return false;
+ }
+ if (isBlank(passwordField.getText())) {
+ setErrorMessage(Messages.error_passwordMissing);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ protected void persistWidgets() {
+ try {
+ ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(packageNsURIName,
+ packageNsURIField.getText());
+ ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(rootObjectTypeName,
+ rootObjectTypeField.getText());
+ ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(persistenceUnitNameName,
+ persistenceUnitNameField.getText());
+ } catch (CoreException cex) {
+ Activator.getDefault().getLog().log(cex.getStatus());
+ }
+ }
+
+ protected Set<String> getPersistenceUnitNames() {
+ return Collections.emptySet();
+ }
+
+ protected void updateDatabaseLoginFieldsFromPersistenceUnit() {
+ databaseURLField.setText(""); //$NON-NLS-1$
+ jdbcDriverField.setText(""); //$NON-NLS-1$
+ userNameField.setText(""); //$NON-NLS-1$
+ passwordField.setText(""); //$NON-NLS-1$
+ }
+
+ protected boolean isBlank(String string) {
+ return string == null || string.trim().length() == 0;
+ }
+
+ protected List<String> getModelNsURIs() {
+ List<String> result = new ArrayList<String>(EPackage.Registry.INSTANCE.keySet());
+ Collections.sort(result, java.text.Collator.getInstance());
+ return result;
+ }
+
+ protected List<String> getModelObjectTypeNames(String nsURI) {
+ List<String> result = new ArrayList<String>();
+ EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(nsURI);
+ if (ePackage != null) {
+ for (EClassifier eClassifier : ePackage.getEClassifiers()) {
+ if (eClassifier instanceof EClass) {
+ EClass eClass = (EClass) eClassifier;
+ if (!eClass.isAbstract()) {
+ result.add(eClass.getName());
+ }
+ }
+ }
+ }
+ Collections.sort(result, java.text.Collator.getInstance());
+ return result;
+ }
+}

Back to the top