Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java446
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java212
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java549
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetActionPage.java203
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetInstallPage.java231
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetVersionChangePage.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewEntityDropDownAction.java261
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java166
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java393
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java234
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java822
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java126
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java137
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java126
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java255
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java384
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java363
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java206
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java33
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java534
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationFigure.java215
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationTablesPage.java189
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationsListComposite.java123
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CardinalityPage.java161
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CascadeDialog.java191
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/ColumnGenPanel.java353
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java518
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java340
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java551
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JoinColumnsPage.java626
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JptUiEntityGenMessages.java123
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizard.java193
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizardPage.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java154
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SWTUtil.java133
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SelectTableDialog.java78
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableAssociationsWizardPage.java757
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableFigure.java76
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableGenPanel.java402
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java379
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java543
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java270
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java269
45 files changed, 0 insertions, 12510 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java
deleted file mode 100644
index 4e18bf961c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import java.util.EventListener;
-import java.util.Iterator;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.preference.PreferenceDialog;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.db.ConnectionAdapter;
-import org.eclipse.jpt.db.ConnectionListener;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.SchemaContainer;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.ui.internal.properties.JpaProjectPropertiesPage;
-import org.eclipse.jpt.utility.internal.ListenerList;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-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.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.PreferencesUtil;
-
-/**
- * Most of the behavior is in DatabaseGroup....
- *
- * We open the wizard page with the JPA project's connection profile and
- * default schema selected (if possible), but then the selections are driven
- * by the user. If the user re-selects the JPA project's connection profile,
- * we will pre-select the project's default schema if possible.
- */
-public class DatabaseSchemaWizardPage extends WizardPage {
-
- final JpaProject jpaProject;
-
- private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
-
- private DatabaseGroup databaseGroup;
-
-
- public DatabaseSchemaWizardPage(JpaProject jpaProject) {
- super("Database Schema"); //$NON-NLS-1$
- if (jpaProject == null) {
- throw new NullPointerException();
- }
- this.jpaProject = jpaProject;
- this.setTitle(JptUiMessages.DatabaseSchemaWizardPage_title);
- this.setMessage(JptUiMessages.DatabaseSchemaWizardPage_desc);
- }
-
- public void createControl(Composite parent) {
- this.setPageComplete(false);
- this.setControl(this.buildTopLevelControl(parent));
- }
-
- private Control buildTopLevelControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setLayout(new GridLayout());
- this.databaseGroup = new DatabaseGroup(composite);
- Dialog.applyDialogFont(parent);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION);
- return composite;
- }
-
- public ConnectionProfile getJpaProjectConnectionProfile() {
- return this.jpaProject.getConnectionProfile();
- }
-
- public Schema getSelectedSchema() {
- return this.databaseGroup.getSelectedSchema();
- }
-
- @Override
- public void dispose() {
- this.databaseGroup.dispose();
- super.dispose();
- }
-
-
- // ********** listeners **********
-
- public void addListener(Listener listener) {
- this.listenerList.add(listener);
- }
-
- public void removeListener(Listener listener) {
- this.listenerList.remove(listener);
- }
-
- void fireSchemaChanged(Schema schema) {
- this.setPageComplete(schema != null);
- for (Listener listener : this.listenerList.getListeners()) {
- listener.selectedSchemaChanged(schema);
- }
- }
-
-
- // ********** listener interface **********
-
- /**
- * Allows clients to listen for changes to the selected connection profile
- * and schema.
- */
- public interface Listener extends EventListener {
- void selectedSchemaChanged(Schema schema);
- }
-
-
- // ********** database group **********
-
- /**
- * schema combo-box
- * add project connection link
- * reconnect link
- */
- class DatabaseGroup {
-
- // these are kept in synch with the selection
- private Schema selectedSchema;
-
- private final Combo schemaComboBox;
-
- private final Link reconnectLink;
-
- private Link addJpaProjectConnectionLink;
-
- private final ConnectionListener connectionListener;
-
-
- // ********** construction **********
-
- DatabaseGroup(Composite composite) {
- super();
-
- Group group = new Group(composite, SWT.NONE);
- group.setLayout(new GridLayout(2, false)); // false = do not make columns equal width
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- group.setText(JptUiMessages.DatabaseSchemaWizardPage_schemaSettings);
- // TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, JpaHelpContextIds.XXX);
-
- // schema combo-box
- this.buildLabel(group, 1, JptUiMessages.DatabaseSchemaWizardPage_schema);
- this.schemaComboBox = this.buildComboBox(group, this.buildSchemaComboBoxSelectionListener());
-
- String message = (this.projectHasAConnection()) ?
- JptUiMessages.DatabaseSchemaWizardPage_schemaInfo :
- JptUiMessages.DatabaseSchemaWizardPage_connectionInfo;
-
- this.buildLabel(group, 2, message);
-
- // add project's connection link
- if( ! this.projectHasAConnection()) {
- this.addJpaProjectConnectionLink = this.buildLink(group,
- JptUiMessages.DatabaseSchemaWizardPage_addConnectionToProject,
- this.buildAddJpaProjectConnectionLinkListener());
- }
-
- // reconnect link
- this.reconnectLink = this.buildLink(group, JptUiMessages.DatabaseSchemaWizardPage_connectLink, this.buildReconnectLinkSelectionListener());
- this.reconnectLink.setEnabled(true);
-
- this.selectedSchema = this.getDefaultSchema();
-
- if (this.selectedSchema != null) {
- DatabaseSchemaWizardPage.this.fireSchemaChanged(this.selectedSchema);
- }
-
- this.connectionListener = this.buildConnectionListener();
- this.addJpaProjectConnectionProfileListener(this.connectionListener);
-
- this.updateSchemaComboBox();
- this.updateReconnectLink();
- }
-
-
- // ********** intra-wizard methods **********
-
- Schema getSelectedSchema() {
- return this.selectedSchema;
- }
-
- void dispose() {
- if(this.projectHasAConnection()) {
- this.getJpaProjectConnectionProfile().removeConnectionListener(this.connectionListener);
- }
- }
-
-
- // ********** internal methods **********
-
- void addJpaProjectConnectionListener() {
- this.addJpaProjectConnectionProfileListener(this.connectionListener);
- }
-
-
- private void addJpaProjectConnectionProfileListener(ConnectionListener listener) {
- if(this.projectHasAConnection()) {
- this.getJpaProjectConnectionProfile().addConnectionListener(listener);
- }
- }
-
- private boolean projectHasAConnection() {
- return this.getJpaProjectConnectionProfile() != null;
- }
-
- /**
- * this can return null;
- * called at start-up and when the selected connection profile changes
- */
- private ConnectionProfile getJpaProjectConnectionProfile() {
- return DatabaseSchemaWizardPage.this.jpaProject.getConnectionProfile();
- }
-
- /**
- * this can return null;
- * called at start-up and when the selected connection profile changes
- */
- private Schema getDefaultSchema() {
- return DatabaseSchemaWizardPage.this.jpaProject.getDefaultDbSchema();
- }
-
- private SchemaContainer getDefaultSchemaContainer() {
- return DatabaseSchemaWizardPage.this.jpaProject.getDefaultDbSchemaContainer();
- }
-
- /**
- * called at start-up and when the selected connection profile changes
- */
- private void updateReconnectLink() {
- this.reconnectLink.setEnabled(this.reconnectLinkCanBeEnabled());
- }
-
- void updateAddJpaProjectConnectionLink() {
- this.addJpaProjectConnectionLink.setEnabled(this.addJpaProjectConnectionLinkCanBeEnabled());
- }
-
- private boolean reconnectLinkCanBeEnabled() {
- if(this.projectHasAConnection()) {
- return this.getJpaProjectConnectionProfile().isInactive();
- }
- return false;
- }
-
- private boolean addJpaProjectConnectionLinkCanBeEnabled() {
- return ! this.projectHasAConnection();
- }
-
- /**
- * the schema combo-box is updated at start-up and
- * when the selected connection profile changes
- */
- private void updateSchemaComboBox() {
- this.schemaComboBox.removeAll();
- for (Iterator<String> stream = this.schemaNames(); stream.hasNext(); ) {
- this.schemaComboBox.add(stream.next());
- }
- // the current schema *should* be in the current connection profile
- if (this.selectedSchema != null) {
- this.schemaComboBox.select(this.schemaComboBox.indexOf(this.selectedSchema.getName()));
- }
- }
-
- private Iterator<String> schemaNames() {
- SchemaContainer sc = this.getDefaultSchemaContainer();
- // use schema *names* since the combo-box is read-only
- return (sc != null) ? sc.sortedSchemaNames() : EmptyIterator.<String>instance();
- }
-
- // ********** listener callbacks **********
-
- void selectedSchemaChanged() {
- Schema old = this.selectedSchema;
- this.selectedSchema = this.getDefaultSchemaContainer().getSchemaNamed(this.schemaComboBox.getText());
- if (this.selectedSchema != old) {
- DatabaseSchemaWizardPage.this.fireSchemaChanged(this.selectedSchema);
- }
- }
-
- void reconnect() {
- this.getJpaProjectConnectionProfile().connect();
- // everything should be synchronized when we get the resulting open event
- }
-
- /**
- * called when
- * - a connection is set to the Jpa project
- * - the connection was opened
- * - the connection was closed (never happens?)
- * we need to update the schema stuff and the reconnect link
- */
- void connectionChanged() {
- Schema old = this.selectedSchema;
- this.selectedSchema = this.getDefaultSchema();
- if (this.selectedSchema != old) {
- DatabaseSchemaWizardPage.this.fireSchemaChanged(this.selectedSchema);
- }
- this.updateSchemaComboBox();
- this.updateReconnectLink();
- }
-
-
- // ********** listeners **********
-
- private SelectionListener buildSchemaComboBoxSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.selectedSchemaChanged();
- }
- @Override
- public String toString() {
- return "DatabaseSchemaWizardPage schema combo-box selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private SelectionListener buildReconnectLinkSelectionListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.reconnect();
- }
- @Override
- public String toString() {
- return "DatabaseSchemaWizardPage reconnect link selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile cp) {
- this.connectionChanged();
- }
- @Override // this probably won't ever get called...
- public void closed(ConnectionProfile cp) {
- this.connectionChanged();
- }
- private void connectionChanged() {
- Display.getDefault().asyncExec(
- new Runnable() {
- public void run() {
- DatabaseGroup.this.connectionChanged();
- }
- }
- );
- }
- @Override
- public String toString() {
- return "DatabaseSchemaWizardPage connection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private SelectionListener buildAddJpaProjectConnectionLinkListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- DatabaseGroup.this.promptToConfigJpaProjectConnection();
-
- DatabaseGroup.this.addJpaProjectConnectionListener();
- DatabaseGroup.this.updateAddJpaProjectConnectionLink();
- DatabaseGroup.this.connectionChanged();
- }
- @Override
- public String toString() {
- return "DatabaseSchemaWizardPage AddProjectConnection link selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- void promptToConfigJpaProjectConnection() {
- PreferenceDialog dialog =
- PreferencesUtil.createPropertyDialogOn(
- getShell(), DatabaseSchemaWizardPage.this.jpaProject.getProject(),
- JpaProjectPropertiesPage.PROP_ID,
- null,
- null);
- dialog.open();
- }
-
- // ********** UI components **********
-
- /**
- * build and return a label
- */
- private Label buildLabel(Composite parent, int span, String text) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- label.setLayoutData(gd);
- return label;
- }
-
- /**
- * build and return a combo-box
- */
- private Combo buildComboBox(Composite parent, SelectionListener listener) {
- Combo combo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- combo.addSelectionListener(listener);
- return combo;
- }
-
- /**
- * build and return a link
- */
- private Link buildLink(Composite parent, String text, SelectionListener listener) {
- Link link = new Link(parent, SWT.NONE);
- GridData data = new GridData(GridData.END, GridData.CENTER, false, false);
- data.horizontalSpan = 2;
- link.setLayoutData(data);
- link.setText(text);
- link.addSelectionListener(listener);
- return link;
- }
-
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java
deleted file mode 100644
index fec614db5f..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.db.Column;
-import org.eclipse.jpt.db.ForeignKey;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.gen.internal.old.EntityGenerator;
-import org.eclipse.jpt.gen.internal.old.PackageGenerator;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-
-/**
- * two pages:
- * - a Database Schema page that allows the user to select a schema
- * - a Generate Entities page that allows the user to select which tables in
- * the selected schema are to be used and to configure Entity names
- */
-public class GenerateEntitiesWizard extends Wizard {
-
- private final JpaProject jpaProject;
-
- private final IStructuredSelection selection;
-
- private DatabaseSchemaWizardPage dbSchemaPage;
-
- private GenerateEntitiesWizardPage generateEntitiesPage;
-
- private final PackageGenerator.Config packageGeneratorConfig;
-
- private final EntityGenerator.Config entityGeneratorConfig;
-
- private boolean synchronizePersistenceXml;
-
-
- public GenerateEntitiesWizard(JpaProject jpaProject, IStructuredSelection selection) {
- super();
- this.jpaProject = jpaProject;
- this.selection = selection;
- this.packageGeneratorConfig = new PackageGenerator.Config();
- this.entityGeneratorConfig = new EntityGenerator.Config();
- this.setWindowTitle(JptUiMessages.GenerateEntitiesWizard_generateEntities);
- }
-
- @Override
- public void addPages() {
- super.addPages();
- this.dbSchemaPage = new DatabaseSchemaWizardPage(this.jpaProject);
- this.dbSchemaPage.addListener(new SchemaPageListener());
- this.addPage(this.dbSchemaPage);
-
- this.generateEntitiesPage = new GenerateEntitiesWizardPage();
- this.addPage(this.generateEntitiesPage);
- this.generateEntitiesPage.init(this.selection);
- }
-
- @Override
- public boolean canFinish() {
- return this.generateEntitiesPage.isPageComplete();
- }
-
- @Override
- public boolean performFinish() {
- this.packageGeneratorConfig.setPackageFragment(this.buildPackageFragment());
-
- this.entityGeneratorConfig.setConvertToJavaStyleIdentifiers(this.generateEntitiesPage.convertToJavaStyleIdentifiers());
- this.entityGeneratorConfig.setFieldAccessType(this.generateEntitiesPage.fieldAccessType());
- this.entityGeneratorConfig.setCollectionTypeName(this.generateEntitiesPage.getCollectionTypeName());
- this.entityGeneratorConfig.setCollectionAttributeNameSuffix(this.generateEntitiesPage.getCollectionAttributeNameSuffix());
- this.entityGeneratorConfig.setFieldVisibility(this.generateEntitiesPage.getFieldVisibility());
- this.entityGeneratorConfig.setMethodVisibility(this.generateEntitiesPage.getMethodVisibility());
- this.entityGeneratorConfig.setGenerateGettersAndSetters(this.generateEntitiesPage.generateGettersAndSetters());
- this.entityGeneratorConfig.setGenerateDefaultConstructor(this.generateEntitiesPage.generateDefaultConstructor());
- this.entityGeneratorConfig.setSerializable(this.generateEntitiesPage.serializable());
- this.entityGeneratorConfig.setGenerateSerialVersionUID(this.generateEntitiesPage.generateSerialVersionUID());
- this.entityGeneratorConfig.setGenerateEmbeddedIdForCompoundPK(this.generateEntitiesPage.generateEmbeddedIdForCompoundPK());
- this.entityGeneratorConfig.setEmbeddedIdAttributeName(this.generateEntitiesPage.getEmbeddedIdAttributeName());
- this.entityGeneratorConfig.setPrimaryKeyMemberClassName(this.generateEntitiesPage.getPrimaryKeyMemberClassName());
- for (Map.Entry<Table, String> entry : this.generateEntitiesPage.getSelectedTables().entrySet()) {
- this.entityGeneratorConfig.addTable(entry.getKey(), entry.getValue());
- }
- // the name builder comes from the JPA platform
- this.entityGeneratorConfig.setDatabaseAnnotationNameBuilder(this.buildDatabaseAnnotationNameBuilder());
-
- this.synchronizePersistenceXml = this.generateEntitiesPage.synchronizePersistenceXml();
-
- return true;
- }
-
- private EntityGenerator.DatabaseAnnotationNameBuilder buildDatabaseAnnotationNameBuilder() {
- return new LocalDatabaseAnnotationNameBuilder(this.jpaProject.getJpaPlatform().getEntityGeneratorDatabaseAnnotationNameBuilder());
- }
-
- private IPackageFragment buildPackageFragment() {
- IPackageFragmentRoot packageFragmentRoot = this.generateEntitiesPage.getPackageFragmentRoot();
- IPackageFragment packageFragment = this.generateEntitiesPage.getPackageFragment();
-
- if (packageFragment == null) {
- packageFragment= packageFragmentRoot.getPackageFragment(""); //$NON-NLS-1$
- }
-
- if (packageFragment.exists()) {
- return packageFragment;
- }
-
- try {
- return packageFragmentRoot.createPackageFragment(packageFragment.getElementName(), true, null);
- }
- catch (JavaModelException ex) {
- throw new RuntimeException(ex);
- }
- }
-
-
- // ********** intra-wizard methods **********
-
- Collection<Table> getPossibleTables() {
- return this.buildTables(this.dbSchemaPage.getSelectedSchema());
- }
-
- JpaProject getJpaProject() {
- return this.jpaProject;
- }
-
- void selectedSchemaChanged(Schema schema) {
- this.generateEntitiesPage.setPossibleTables(this.buildTables(schema));
- }
-
- private Collection<Table> buildTables(Schema schema) {
- return (schema == null) ?
- Collections.<Table>emptySet()
- :
- CollectionTools.collection(schema.tables());
- }
-
-
- // ********** public methods - settings **********
-
- public PackageGenerator.Config getPackageGeneratorConfig() {
- return this.packageGeneratorConfig;
- }
-
- public EntityGenerator.Config getEntityGeneratorConfig() {
- return this.entityGeneratorConfig;
- }
-
- public boolean synchronizePersistenceXml(){
- return this.synchronizePersistenceXml;
- }
-
-
- // ********** name builder adapter **********
-
- /**
- * adapt the JPA platform-supplied builder to the builder interface
- * expected by the entity generator
- */
- static class LocalDatabaseAnnotationNameBuilder implements EntityGenerator.DatabaseAnnotationNameBuilder {
- private EntityGeneratorDatabaseAnnotationNameBuilder builder;
- LocalDatabaseAnnotationNameBuilder(EntityGeneratorDatabaseAnnotationNameBuilder builder) {
- super();
- this.builder = builder;
- }
- public String buildTableAnnotationName(String entityName, Table table) {
- return this.builder.buildTableAnnotationName(entityName, table);
- }
- public String buildColumnAnnotationName(String attributeName, Column column) {
- return this.builder.buildColumnAnnotationName(attributeName, column);
- }
- public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) {
- return this.builder.buildJoinColumnAnnotationName(attributeName, foreignKey);
- }
- public String buildJoinColumnAnnotationName(Column column) {
- return this.builder.buildJoinColumnAnnotationName(column);
- }
- public String buildJoinTableAnnotationName(Table table) {
- return this.builder.buildJoinTableAnnotationName(table);
- }
- }
-
-
- // ********** schema page listener **********
-
- /**
- * listen for when the Database Connection page changes its selected schema
- * so we can keep the Generate Entities page in synch
- */
- class SchemaPageListener implements DatabaseSchemaWizardPage.Listener {
- public void selectedSchemaChanged(Schema schema) {
- GenerateEntitiesWizard.this.selectedSchemaChanged(schema);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java
deleted file mode 100644
index d6f2175ee0..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.ICellModifier;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.gen.internal.old.EntityGenTools;
-import org.eclipse.jpt.gen.internal.old.EntityGenerator;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.ui.internal.util.TableLayoutComposite;
-import org.eclipse.jpt.utility.internal.NameTools;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.PlatformUI;
-
-// TODO add numerous settings to UI...
-// TODO validate list of user-approved entity names:
-// no duplicates (case-sensitive)
-// valid Java identifiers @see NameTools.stringConsistsOfJavaIdentifierCharacters(String)
-// no Java reserved words @see NameTools.JAVA_RESERVED_WORDS_SET
-class GenerateEntitiesWizardPage extends NewTypeWizardPage {
-
- CheckboxTableViewer tableTable;
- Button synchronizeClassesCheckBox;
-
- // TODO if this flag changes we need to re-calculate the entity names...
- // (at the moment, it does not change because it is not visible to the user...)
- private boolean convertToJavaStyleIdentifiers = true;
- private boolean fieldAccessType = true;
- private String collectionTypeName = Set.class.getName();
- private String collectionAttributeNameSuffix = "_collection"; //$NON-NLS-1$
- private int fieldVisibility = EntityGenerator.Config.PRIVATE;
- private int methodVisibility = EntityGenerator.Config.PUBLIC;
- private boolean generateGettersAndSetters = true;
- private boolean generateDefaultConstructor = true;
- private boolean serializable = true;
- private boolean generateSerialVersionUID = true;
- private boolean generateEmbeddedIdForCompoundPK = true;
- private String embeddedIdAttributeName = "pk"; //$NON-NLS-1$
- private String primaryKeyMemberClassName = "PK"; //$NON-NLS-1$
-
- // key = table; value = entity name
- private HashMap<Table, String> entityNames;
-
- private boolean synchronizePersistenceXml = false;
-
- static final String[] TABLE_TABLE_COLUMN_PROPERTIES = { "table", "entityName" }; //$NON-NLS-1$ //$NON-NLS-2$
- private static final int TABLE_COLUMN_INDEX = 0;
- private static final int ENTITY_NAME_COLUMN_INDEX = 1;
-
-
- GenerateEntitiesWizardPage() {
- super(true, "Generate Entities"); //$NON-NLS-1$
- setTitle(JptUiMessages.GenerateEntitiesWizardPage_generateEntities);
- setMessage(JptUiMessages.GenerateEntitiesWizardPage_chooseEntityTable);
- }
-
- // -------- Initialization ---------
- /**
- * The wizard owning this page is responsible for calling this method with the
- * current selection. The selection is used to initialize the fields of the wizard
- * page.
- *
- * @param selection used to initialize the fields
- */
- void init(IStructuredSelection selection) {
- IJavaElement jelem= getInitialJavaElement(selection);
- initContainerPage(jelem);
- initTypePage(jelem);
- doStatusUpdate();
- }
-
- public void createControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 4;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.DIALOG_GENERATE_ENTITIES);
-
- createContainerControls(composite, nColumns);
- createPackageControls(composite, nColumns);
-
- this.synchronizeClassesCheckBox = new Button(composite, SWT.CHECK);
- synchronizeClassesCheckBox.setText(JptUiMessages.GenerateEntitiesWizardPage_synchronizeClasses);
- synchronizeClassesCheckBox.addSelectionListener(this.buildSynchClassesSelectionListener());
-
- Group tablesGroup = new Group(composite, SWT.SHADOW_ETCHED_IN);
- tablesGroup.setLayout(new GridLayout(2, false));
- tablesGroup.setText(JptUiMessages.GenerateEntitiesWizardPage_tables);
- GridData data = new GridData();
- data.horizontalSpan = 4;
- data.verticalAlignment = SWT.FILL;
- data.horizontalAlignment = SWT.FILL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- tablesGroup.setLayoutData(data);
-
- createTablesSelectionControl(tablesGroup);
- createButtonComposite(tablesGroup);
-
- this.initTablesSelectionControl();
-
- //set initial selection state of the synchronize classes checkbox
- synchronizeClassesCheckBox.setSelection( ! this.getGenEntitiesWizard().getJpaProject().discoversAnnotatedClasses());
- setSynchronizePersistenceXml(synchronizeClassesCheckBox.getSelection());
-
- PlatformUI.getWorkbench().getHelpSystem().setHelp(this.tableTable.getControl(), JpaHelpContextIds.DIALOG_GENERATE_ENTITIES_TABLES);
-
- setControl(composite);
- this.setPageComplete(false);
- }
-
- private GenerateEntitiesWizard getGenEntitiesWizard() {
- return (GenerateEntitiesWizard) this.getWizard();
- }
-
- void selectAllTables(){
- this.tableTable.setAllChecked(true);
- doStatusUpdate();
- }
-
- void deselectAllTables(){
- this.tableTable.setAllChecked(false);
- doStatusUpdate();
- }
-
- private void initTablesSelectionControl() {
- this.setPossibleTables(this.getGenEntitiesWizard().getPossibleTables());
- }
-
- void setPossibleTables(Collection<Table> possibleTables) {
- if (this.tableTable == null) {
- return; // the wizard has called this method before our widgets are built
- }
- this.entityNames = new HashMap<Table, String>(possibleTables.size());
- for (Table table : possibleTables) {
- String tableName = table.getName();
- String entityName = (this.convertToJavaStyleIdentifiers) ?
- EntityGenTools.convertToUniqueJavaStyleClassName(tableName, entityNames.values())
- :
- NameTools.uniqueNameFor(tableName, entityNames.values());
- this.entityNames.put(table, entityName);
- }
- this.tableTable.setInput(possibleTables);
- }
-
- private void createTablesSelectionControl(Composite parent) {
- TableLayoutComposite layout= new TableLayoutComposite(parent, SWT.NONE);
- addColumnLayoutData(layout);
-
- final org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(layout, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- TableColumn tableNameColumn = new TableColumn(table, SWT.NONE, TABLE_COLUMN_INDEX);
- tableNameColumn.setText(JptUiMessages.GenerateEntitiesWizardPage_tableColumn);
- tableNameColumn.setResizable(true);
-
- TableColumn entityNameColumn = new TableColumn(table, SWT.NONE, ENTITY_NAME_COLUMN_INDEX);
- entityNameColumn.setText(JptUiMessages.GenerateEntitiesWizardPage_entityNameColumn);
- entityNameColumn.setResizable(true);
-
- GridData gd= new GridData(GridData.FILL_BOTH);
- gd.heightHint= SWTUtil.getTableHeightHint(table, 20);
- gd.widthHint = 600;
- layout.setLayoutData(gd);
-
- this.tableTable = new CheckboxTableViewer(table);
- this.tableTable.setUseHashlookup(true);
- this.tableTable.setLabelProvider(this.buildTableTableLabelProvider());
- this.tableTable.setContentProvider(this.buildTableTableContentProvider());
- this.tableTable.setSorter(new ViewerSorter() {
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- return ((Table) e1).getName().compareTo(((Table) e2).getName());
- }
- });
-
- this.tableTable.addPostSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- handleTablesListSelectionChanged();
- }
- });
-
- table.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.keyCode == SWT.F2 && e.stateMask == SWT.NONE) {
- editEntityNameIfPossible();
- e.doit= false;
- }
- }
- });
-
- this.addCellEditors();
- }
-
- private void createButtonComposite(Group tablesGroup){
- Composite buttonComposite = new Composite(tablesGroup, SWT.NULL);
- GridLayout buttonLayout = new GridLayout(1, false);
- buttonComposite.setLayout(buttonLayout);
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- buttonComposite.setLayoutData(data);
-
- Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
- selectAllButton.setText(JptUiMessages.General_selectAll);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- selectAllButton.setLayoutData(gridData);
- selectAllButton.addSelectionListener(this.buildSelectAllButtonSelectionListener());
-
- Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
- deselectAllButton.setText(JptUiMessages.General_deselectAll);
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- deselectAllButton.setLayoutData(gridData);
- deselectAllButton.addSelectionListener(this.buildDeselectAllButtonSelectionListener());
- }
-
-
- private void addColumnLayoutData(TableLayoutComposite layout) {
- layout.addColumnData(new ColumnWeightData(50, true));
- layout.addColumnData(new ColumnWeightData(50, true));
- }
-
- void editEntityNameIfPossible(){
- Object[] selected = ((IStructuredSelection) this.tableTable.getSelection()).toArray();
- if (selected.length == 1) {
- this.tableTable.editElement(selected[0], ENTITY_NAME_COLUMN_INDEX);
- }
- }
-
- private void addCellEditors() {
- this.tableTable.setColumnProperties(TABLE_TABLE_COLUMN_PROPERTIES);
-
- TextCellEditor[] editors = new TextCellEditor[TABLE_TABLE_COLUMN_PROPERTIES.length];
- editors[ENTITY_NAME_COLUMN_INDEX]= new TextCellEditor(this.tableTable.getTable(), SWT.SINGLE);
-
- this.tableTable.setCellEditors(editors);
- this.tableTable.setCellModifier(this.buildTableTableCellModifier());
- }
-
- void handleTablesListSelectionChanged() {
- this.setPageComplete(true);
- if (this.noTablesAreSelected()) {
- this.setPageComplete(false);
- }
- }
-
- private IBaseLabelProvider buildTableTableLabelProvider() {
- return new TableTableLabelProvider();
- }
-
- private IContentProvider buildTableTableContentProvider() {
- return new TableTableContentProvider();
- }
-
- private ICellModifier buildTableTableCellModifier() {
- return new TableTableCellModifier();
- }
-
- Map<Table, String> getSelectedTables() {
- Object[] checkedElements = this.tableTable.getCheckedElements();
- HashMap<Table, String> selectedTables = new HashMap<Table, String>(checkedElements.length);
- for (Object checkedElement : checkedElements) {
- Table table = (Table) checkedElement;
- selectedTables.put(table, this.entityNames.get(table));
- }
- return selectedTables;
- }
-
- private boolean noTablesAreSelected() {
- return (this.tableTable == null) ? true : (this.tableTable.getCheckedElements().length == 0);
- }
-
- @Override
- protected void handleFieldChanged(String fieldName) {
- super.handleFieldChanged(fieldName);
-
- doStatusUpdate();
- }
-
- private void doStatusUpdate() {
- // status of all used components
- IStatus[] status= new IStatus[] {
- fContainerStatus,
- fPackageStatus
- };
- // the mode severe status will be displayed and the OK button enabled/disabled.
- this.updateStatus(status);
- }
-
- /**
- * Update the status line and the OK button according to the given status
- */
- @Override
- protected void updateStatus(IStatus status) {
- super.updateStatus(status);
- if (this.isPageComplete() && this.noTablesAreSelected()) {
- this.setPageComplete(false);
- }
- }
-
- String getEntityName(Table table) {
- return this.entityNames.get(table);
- }
-
- /**
- * return whether the new entity name is different from the old entity name
- */
- boolean setEntityName(Table table, String entityName) {
- String old = this.entityNames.put(table, entityName);
- return ! entityName.equals(old);
- }
-
- boolean convertToJavaStyleIdentifiers() {
- return this.convertToJavaStyleIdentifiers;
- }
-
- boolean fieldAccessType() {
- return this.fieldAccessType;
- }
-
- String getCollectionTypeName() {
- return this.collectionTypeName;
- }
-
- String getCollectionAttributeNameSuffix() {
- return this.collectionAttributeNameSuffix;
- }
-
- int getFieldVisibility() {
- return this.fieldVisibility;
- }
-
- int getMethodVisibility() {
- return this.methodVisibility;
- }
-
- boolean generateGettersAndSetters() {
- return this.generateGettersAndSetters;
- }
-
- boolean generateDefaultConstructor() {
- return this.generateDefaultConstructor;
- }
-
- boolean serializable() {
- return this.serializable;
- }
-
- boolean generateSerialVersionUID() {
- return this.generateSerialVersionUID;
- }
-
- boolean generateEmbeddedIdForCompoundPK() {
- return this.generateEmbeddedIdForCompoundPK;
- }
-
- boolean synchronizePersistenceXml() {
- return this.synchronizePersistenceXml;
- }
-
- void setSynchronizePersistenceXml(boolean synchronizePersistenceXml){
- this.synchronizePersistenceXml = synchronizePersistenceXml;
- }
-
- String getEmbeddedIdAttributeName() {
- return this.embeddedIdAttributeName;
- }
-
- String getPrimaryKeyMemberClassName() {
- return this.primaryKeyMemberClassName;
- }
-
- private SelectionListener buildSelectAllButtonSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- selectAllTables();
- }
- };
- }
-
- private SelectionListener buildDeselectAllButtonSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- deselectAllTables();
- }
- };
- }
-
- private SelectionListener buildSynchClassesSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- setSynchronizePersistenceXml(synchronizeClassesCheckBox.getSelection());
- }
- };
- }
-
-
- // ********** inner classes **********
-
- class TableTableLabelProvider extends LabelProvider implements ITableLabelProvider {
-
- TableTableLabelProvider() {
- super();
- }
-
- @Override
- public String getText(Object element) {
- return ((Table) element).getName();
- }
-
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (element == null) {
- return null;
- }
- switch (columnIndex) {
- case TABLE_COLUMN_INDEX:
- return ((Table) element).getName();
-
- case ENTITY_NAME_COLUMN_INDEX:
- return GenerateEntitiesWizardPage.this.getEntityName((Table) element);
- }
- throw new IllegalArgumentException("invalid column index: " + columnIndex); //$NON-NLS-1$
- }
-
- }
-
-
- static class TableTableContentProvider implements IStructuredContentProvider {
-
- TableTableContentProvider() {
- super();
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // do nothing
- }
-
- public void dispose() {
- // do nothing
- }
-
- public Object[] getElements(Object inputElement) {
- return ((Collection<?>) inputElement).toArray();
- }
-
- }
-
-
- class TableTableCellModifier implements ICellModifier {
-
- TableTableCellModifier() {
- super();
- }
-
- public boolean canModify(Object element, String property) {
- return property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX]);
- }
-
- public Object getValue(Object element, String property) {
- if (property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX])) {
- return GenerateEntitiesWizardPage.this.getEntityName((Table) element);
- }
- return null;
- }
-
- public void modify(Object element, String property, Object value) {
- if (element instanceof TableItem) {
- element= ((TableItem) element).getData();
- }
- if ( ! (element instanceof Table)) {
- return;
- }
- Table table = (Table) element;
-
- boolean changed = true;
- if (property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX])) {
- changed = GenerateEntitiesWizardPage.this.setEntityName(table, (String) value);
- }
- if (changed) {
- GenerateEntitiesWizardPage.this.tableTable.update(table, new String[] { property });
- }
- }
-
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetActionPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetActionPage.java
deleted file mode 100644
index 950d2e7ad7..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetActionPage.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * 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 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiIcons;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate;
-import org.eclipse.jst.common.project.facet.ui.libprov.LibraryProviderFrameworkUi;
-import org.eclipse.swt.SWT;
-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.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
-import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard;
-import org.eclipse.wst.web.ui.internal.wizards.DataModelFacetInstallPage;
-
-public abstract class JpaFacetActionPage
- extends DataModelFacetInstallPage
- implements JpaFacetDataModelProperties
-{
- protected JpaFacetActionPage(String pageName) {
- super(pageName);
- setTitle(JptUiMessages.JpaFacetWizardPage_title);
- setDescription(JptUiMessages.JpaFacetWizardPage_description);
- setImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER));
- }
-
-
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- composite.setLayout(layout);
-
- addSubComposites(composite);
-
- setUpRuntimeListener();
-
- Dialog.applyDialogFont(parent);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, JpaHelpContextIds.DIALOG_JPA_FACET);
-
- return composite;
- }
-
- protected abstract void addSubComposites(Composite composite);
-
- private void setUpRuntimeListener() {
- final IFacetedProjectWorkingCopy wc = ( (ModifyFacetedProjectWizard) getWizard() ).getFacetedProjectWorkingCopy();
- // must do it manually the first time
- model.setProperty(RUNTIME, wc.getPrimaryRuntime());
- wc.addListener(
- new IFacetedProjectListener() {
- public void handleEvent( final IFacetedProjectEvent event ) {
- model.setProperty(RUNTIME, wc.getPrimaryRuntime());
- }
- },
- IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED
- );
- }
-
- protected Button createButton(Composite container, int span, String text, int style) {
- Button button = new Button(container, SWT.NONE | style);
- button.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- button.setLayoutData(gd);
- return button;
- }
-
- protected Combo createCombo(Composite container, int span, boolean fillHorizontal) {
- Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- GridData gd;
- if (fillHorizontal) {
- gd = new GridData(GridData.FILL_HORIZONTAL);
- }
- else {
- gd = new GridData();
- }
- gd.horizontalSpan = span;
- combo.setLayoutData(gd);
- return combo;
- }
-
- @Override
- protected String[] getValidationPropertyNames() {
- return new String[] {
- PLATFORM_ID,
- CONNECTION,
- USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG,
- USER_OVERRIDE_DEFAULT_CATALOG,
- USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA,
- USER_OVERRIDE_DEFAULT_SCHEMA,
- DISCOVER_ANNOTATED_CLASSES,
- LIBRARY_PROVIDER_DELEGATE
- };
- }
-
- @Override
- public boolean isPageComplete() {
- if (! super.isPageComplete()) {
- return false;
- }
- else {
- IStatus status = model.validate();
- if (status.getSeverity() == IStatus.ERROR) {
- setErrorMessage(status.getMessage());
- return false;
- };
- setErrorMessage(null);
- return true;
- }
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- setErrorMessage();
- }
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-
-
- protected final class PlatformGroup
- {
- private final Combo platformCombo;
-
-
- public PlatformGroup(Composite composite) {
- Group group = new Group(composite, SWT.NONE);
- group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_JPA_PLATFORM);
-
- platformCombo = createCombo(group, 1, true);
- synchHelper.synchCombo(platformCombo, PLATFORM_ID, null);
- }
- }
-
-
- protected final class ClasspathConfigGroup
- {
- public ClasspathConfigGroup(Composite composite) {
-
- final LibraryInstallDelegate librariesInstallDelegate
- = (LibraryInstallDelegate) getDataModel().getProperty(LIBRARY_PROVIDER_DELEGATE);
-
- final Composite librariesComposite
- = (Composite) LibraryProviderFrameworkUi.createInstallLibraryPanel(
- composite, librariesInstallDelegate,
- JptUiMessages.JpaFacetWizardPage_jpaImplementationLabel );
- librariesComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(librariesComposite, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH);
- }
- }
-
-
- protected final class PersistentClassManagementGroup
- {
- private final Button discoverClassesButton;
-
- private final Button listClassesButton;
-
-
- public PersistentClassManagementGroup(Composite composite) {
- Group group = new Group(composite, SWT.NONE);
- group.setText(JptUiMessages.JpaFacetWizardPage_persistentClassManagementLabel);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH);
-
- discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO);
- synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null);
-
- listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO);
- synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetInstallPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetInstallPage.java
deleted file mode 100644
index acae886417..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetInstallPage.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.JptDbPlugin;
-import org.eclipse.jpt.db.ui.internal.DTPUiTools;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.utility.internal.ArrayTools;
-import org.eclipse.swt.SWT;
-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.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.ui.PlatformUI;
-
-public class JpaFacetInstallPage
- extends JpaFacetActionPage
- implements JpaFacetInstallDataModelProperties
-{
- public JpaFacetInstallPage() {
- super("jpt.jpa.facet.install.page"); //$NON-NLS-1$
- }
-
-
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = super.createTopLevelComposite(parent);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.NEW_JPA_PROJECT_JPA_FACET);
- return composite;
- }
-
- @Override
- protected void addSubComposites(Composite composite) {
- new PlatformGroup(composite);
- new ClasspathConfigGroup(composite);
- new ConnectionGroup(composite);
- new PersistentClassManagementGroup(composite);
- new OrmXmlGroup(composite);
- }
-
- @Override
- protected String[] getValidationPropertyNames() {
- String[] validationPropertyNames = super.getValidationPropertyNames();
- return ArrayTools.addAll(
- validationPropertyNames,
- USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH,
- DB_DRIVER_NAME);
- }
-
-
- protected final class ConnectionGroup
- {
- private final Combo connectionCombo;
-
- private Link connectionLink;
-
- private Link connectLink;
-
- private final Button addDriverLibraryButton;
-
- private final Label driverLibraryLabel;
-
- private final Combo driverLibraryCombo;
-
- private final Button overrideDefaultCatalogButton;
-
- private final Label defaultCatalogLabel;
-
- private final Combo defaultCatalogCombo;
-
- private final Button overrideDefaultSchemaButton;
-
- private final Label defaultSchemaLabel;
-
- private final Combo defaultSchemaCombo;
-
-
- public ConnectionGroup(Composite composite) {
- Group group = new Group(composite, SWT.NONE);
- group.setText(JptUiMessages.JpaFacetWizardPage_connectionLabel);
- group.setLayout(new GridLayout(3, false));
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE);
-
- connectionCombo = createCombo(group, 3, true);
- synchHelper.synchCombo(connectionCombo, CONNECTION, null);
- connectionCombo.addSelectionListener(
- new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateConnectLink();
- }
- });
-
- connectionLink = new Link(group, SWT.NONE);
- GridData data = new GridData(GridData.END, GridData.CENTER, false, false);
- data.horizontalSpan = 2;
- connectionLink.setLayoutData(data);
- connectionLink.setText(JptUiMessages.JpaFacetWizardPage_connectionLink);
- connectionLink.addSelectionListener(
- new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- openNewConnectionWizard();
- }
- }
- );
-
- connectLink = new Link(group, SWT.NONE);
- data = new GridData(GridData.END, GridData.CENTER, false, false);
- data.horizontalSpan = 2;
- connectLink.setLayoutData(data);
- connectLink.setText(JptUiMessages.JpaFacetWizardPage_connectLink);
- connectLink.setEnabled(false);
- connectLink.addSelectionListener(
- new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- openConnectionProfile();
- }
- });
-
- addDriverLibraryButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_addDriverLibraryLabel, SWT.CHECK);
- addDriverLibraryButton.setSelection(false);
- synchHelper.synchCheckbox(addDriverLibraryButton, USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, null);
-
- driverLibraryLabel = new Label(group, SWT.LEFT);
- driverLibraryLabel.setText(JptUiMessages.JpaFacetWizardPage_driverLibraryLabel);
- GridData gd = new GridData();
- gd.horizontalSpan = 1;
- driverLibraryLabel.setLayoutData(gd);
-
- driverLibraryCombo = createCombo(group, 1, true);
- synchHelper.synchCombo(
- driverLibraryCombo, DB_DRIVER_NAME,
- new Control[] {driverLibraryLabel});
-
- overrideDefaultCatalogButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, SWT.CHECK);
- overrideDefaultCatalogButton.setSelection(false);
- synchHelper.synchCheckbox(overrideDefaultCatalogButton, USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, null);
-
- defaultCatalogLabel = new Label(group, SWT.LEFT);
- defaultCatalogLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultCatalogLabel);
- gd = new GridData();
- gd.horizontalSpan = 1;
- defaultCatalogLabel.setLayoutData(gd);
-
- defaultCatalogCombo = createCombo(group, 1, true);
- synchHelper.synchCombo(
- defaultCatalogCombo, USER_OVERRIDE_DEFAULT_CATALOG,
- new Control[] {defaultCatalogLabel});
-
- overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK);
- overrideDefaultSchemaButton.setSelection(false);
- synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null);
-
- defaultSchemaLabel = new Label(group, SWT.LEFT);
- defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel);
- gd = new GridData();
- gd.horizontalSpan = 1;
- defaultSchemaLabel.setLayoutData(gd);
-
- defaultSchemaCombo = createCombo(group, 1, true);
- synchHelper.synchCombo(
- defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA,
- new Control[] {defaultSchemaLabel});
- }
-
- private void openNewConnectionWizard() {
- String connectionName = DTPUiTools.createNewConnectionProfile();
- if (connectionName != null) {
- model.setProperty(CONNECTION, connectionName);
- }
- }
-
- private void openConnectionProfile() {
- ConnectionProfile cp = getConnectionProfile();
- if (cp != null) {
- cp.connect();
- model.setBooleanProperty(CONNECTION_ACTIVE, cp.isActive());
- updateConnectLink();
- }
- }
-
- private void updateConnectLink() {
- ConnectionProfile cp = this.getConnectionProfile();
- connectLink.setEnabled((cp != null) && cp.isDisconnected());
- addDriverLibraryButton.setEnabled(cp != null);
- }
-
- private ConnectionProfile getConnectionProfile() {
- // we just use the connection profile to log in, so go the the db plug-in
- return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(model.getStringProperty(CONNECTION));
- }
- }
-
-
- protected final class OrmXmlGroup
- {
- private final Button createOrmXmlButton;
-
-
- public OrmXmlGroup(Composite composite) {
- Composite group = new Composite(composite, SWT.NONE);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_CREATE_ORM);
-
- createOrmXmlButton = new Button(group, SWT.CHECK);
- createOrmXmlButton.setText(JptUiMessages.JpaFacetWizardPage_createOrmXmlButton);
- synchHelper.synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetVersionChangePage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetVersionChangePage.java
deleted file mode 100644
index 9be0ce0570..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetVersionChangePage.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * 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 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import org.eclipse.swt.widgets.Composite;
-
-public class JpaFacetVersionChangePage
- extends JpaFacetActionPage
-{
- public JpaFacetVersionChangePage() {
- super("jpt.jpa.facet.version-change.page"); //$NON-NLS-1$
- }
-
-
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = super.createTopLevelComposite(parent);
- // TODO
- //this.getHelpSystem().setHelp(composite, JpaHelpContextIds.NEW_JPA_PROJECT_JPA_FACET);
- return composite;
- }
-
- @Override
- protected void addSubComposites(Composite composite) {
- new PlatformGroup(composite);
- new ClasspathConfigGroup(composite);
- //new ConnectionGroup(composite);
- //new PersistentClassManagementGroup(composite);
- }
-
- @Override
- protected String[] getValidationPropertyNames() {
- // nothing new here *just* yet
- return super.getValidationPropertyNames();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewEntityDropDownAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewEntityDropDownAction.java
deleted file mode 100644
index 2b67c09a9e..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewEntityDropDownAction.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- * Oracle - copied and modified from NewJavaEEDropDownAction and NewTypeDropDownAction
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ActionContributionItem;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuCreator;
-import org.eclipse.jface.layout.PixelConverter;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
-import org.eclipse.jdt.internal.ui.util.CoreUtility;
-
-
-/**
- * A type wizard is added to the type drop down if it has a paramater 'javatype':
- * <wizard
- * name="My JPT Wizard"
- * icon="icons/wiz.gif"
- * category="mycategory"
- * id="xx.MyWizard">
- * <class class="org.xx.MyWizard">
- * <parameter name="jptartifact" value="true"/>
- * </class>
- * <description>
- * My JPT Wizard
- * </description>
- * </wizard>
- */
-public class NewEntityDropDownAction extends Action implements IMenuCreator, IWorkbenchWindowPulldownDelegate2 {
-
- public static class OpenJptWizardAction extends AbstractOpenWizardAction implements Comparable<Object> {
-
- private final static String ATT_NAME = "name";//$NON-NLS-1$
- private final static String ATT_CLASS = "class";//$NON-NLS-1$
- private final static String ATT_ICON = "icon";//$NON-NLS-1$
- private static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
-
- private IConfigurationElement fConfigurationElement;
- private int menuIndex;
-
- public OpenJptWizardAction(IConfigurationElement element) {
- this.fConfigurationElement= element;
- setText(element.getAttribute(ATT_NAME));
-
- String description= getDescriptionFromConfig(this.fConfigurationElement);
- setDescription(description);
- setToolTipText(description);
- setImageDescriptor(getIconFromConfig(this.fConfigurationElement));
- setMenuIndex(getMenuIndexFromConfig(this.fConfigurationElement));
- }
-
- private String getDescriptionFromConfig(IConfigurationElement config) {
- IConfigurationElement [] children = config.getChildren(TAG_DESCRIPTION);
- if (children.length>=1) {
- return children[0].getValue();
- }
- return ""; //$NON-NLS-1$
- }
-
- private ImageDescriptor getIconFromConfig(IConfigurationElement config) {
- String iconName = config.getAttribute(ATT_ICON);
- if (iconName != null) {
- return AbstractUIPlugin.imageDescriptorFromPlugin(config.getContributor().getName(), iconName);
- }
- return null;
- }
-
- private int getMenuIndexFromConfig(IConfigurationElement config) {
- IConfigurationElement[] classElements = config.getChildren(TAG_CLASS);
- if (classElements.length > 0) {
- for (IConfigurationElement classElement : classElements) {
- IConfigurationElement[] paramElements = classElement.getChildren(TAG_PARAMETER);
- for (IConfigurationElement paramElement : paramElements) {
- if (ATT_MENUINDEX.equals(paramElement.getAttribute(TAG_NAME))) {
- return Integer.parseInt(paramElement.getAttribute(TAG_VALUE));
- }
- }
- }
- }
- return Integer.MAX_VALUE;
- }
-
- @Override
- public void run() {
- Shell shell = getShell();
- try {
- INewWizard wizard = createWizard();
- wizard.init(PlatformUI.getWorkbench(), getSelection());
-
- WizardDialog dialog = new WizardDialog(shell, wizard);
- PixelConverter converter = new PixelConverter(JFaceResources.getDialogFont());
- dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
- dialog.create();
- int res = dialog.open();
-
- notifyResult(res == Window.OK);
- } catch (CoreException e) {
- Logger.getLogger().log(e);
- }
- }
-
- @Override
- protected INewWizard createWizard() throws CoreException {
- return (INewWizard) CoreUtility.createExtension(fConfigurationElement, ATT_CLASS);
- }
-
- public int getMenuIndex() {
- return this.menuIndex;
- }
-
- public void setMenuIndex(int menuIndex) {
- this.menuIndex = menuIndex;
- }
-
- public int compareTo(Object o) {
- OpenJptWizardAction action = (OpenJptWizardAction) o;
- return getMenuIndex() - action.getMenuIndex();
- }
-
- }
-
-
-
- private final static String TAG_WIZARD = "wizard";//$NON-NLS-1$
- private final static String ATT_JPTARTIFACT = "jptartifact";//$NON-NLS-1$
-
- private final static String TAG_PARAMETER = "parameter";//$NON-NLS-1$
- private final static String TAG_NAME = "name";//$NON-NLS-1$
- private final static String TAG_VALUE = "value";//$NON-NLS-1$
- protected final static String ATT_MENUINDEX = "menuIndex";//$NON-NLS-1$
-
- private static final String PL_NEW = "newWizards"; //$NON-NLS-1$
- private static final String TAG_CLASS = "class"; //$NON-NLS-1$
-
- private Menu fMenu;
-
- private Shell fWizardShell;
-
- public NewEntityDropDownAction() {
- this.fMenu= null;
- setMenuCreator(this);
- //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
- }
-
- public void dispose() {
- if (this.fMenu != null) {
- this.fMenu.dispose();
- this.fMenu= null;
- }
- }
-
- public Menu getMenu(Menu parent) {
- return null;
- }
-
- public Menu getMenu(Control parent) {
- if (this.fMenu == null) {
- this.fMenu = new Menu(parent);
- OpenJptWizardAction[] actions = getActionFromDescriptors();
- for (int i = 0; i < actions.length; i++) {
- OpenJptWizardAction curr = actions[i];
- curr.setShell(this.fWizardShell);
- ActionContributionItem item = new ActionContributionItem(curr);
- item.fill(this.fMenu, -1);
- }
-
- }
- return this.fMenu;
- }
-
- @Override
- public void run() {
- getDefaultAction().run();
- }
-
- public Action getDefaultAction() {
- Action[] actions = getActionFromDescriptors();
- if (actions.length > 0)
- return actions[0];
- return null;
- }
-
- public static OpenJptWizardAction[] getActionFromDescriptors() {
- ArrayList<OpenJptWizardAction> containers= new ArrayList<OpenJptWizardAction>();
-
- IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, PL_NEW);
- if (extensionPoint != null) {
- IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement element= elements[i];
- if (element.getName().equals(TAG_WIZARD) && isJptArtifactWizard(element)) {
- containers.add(new OpenJptWizardAction(element));
- }
- }
- }
- OpenJptWizardAction[] actions = containers.toArray(new OpenJptWizardAction[containers.size()]);
- Arrays.sort(actions);
- return actions;
- }
-
- private static boolean isJptArtifactWizard(IConfigurationElement element) {
- IConfigurationElement[] classElements= element.getChildren(TAG_CLASS);
- if (classElements.length > 0) {
- for (int i= 0; i < classElements.length; i++) {
- IConfigurationElement[] paramElements= classElements[i].getChildren(TAG_PARAMETER);
- for (int k = 0; k < paramElements.length; k++) {
- IConfigurationElement curr= paramElements[k];
- if (ATT_JPTARTIFACT.equals(curr.getAttribute(TAG_NAME))) {
- return Boolean.valueOf(curr.getAttribute(TAG_VALUE)).booleanValue();
- }
- }
- }
- }
- return false;
- }
-
- public void init(IWorkbenchWindow window) {
- fWizardShell= window.getShell();
- }
-
- public void run(IAction action) {
- run();
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java
deleted file mode 100644
index 437a2c4b9f..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. 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. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jst.j2ee.ui.project.facet.UtilityProjectFirstPage;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-
-public class NewJpaProjectFirstPage extends UtilityProjectFirstPage
-{
- public NewJpaProjectFirstPage(IDataModel dataModel, String pageName) {
- super(dataModel, pageName);
- setTitle(JptUiMessages.NewJpaProjectWizard_firstPage_title);
- setDescription(JptUiMessages.NewJpaProjectWizard_firstPage_description);
- setInfopopID(JpaHelpContextIds.NEW_JPA_PROJECT);
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java
deleted file mode 100644
index 53d34954f8..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. 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. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JptUiIcons;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jst.j2ee.ui.project.facet.UtilityProjectWizard;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-
-public class NewJpaProjectWizard extends UtilityProjectWizard {
-
- public NewJpaProjectWizard() {
- super();
- setWindowTitle(JptUiMessages.NewJpaProjectWizard_title);
- }
-
- public NewJpaProjectWizard(IDataModel model) {
- super(model);
- setWindowTitle(JptUiMessages.NewJpaProjectWizard_title);
- }
-
- // TODO - when we have a data model to add
-// protected IDataModel createDataModel() {
-// return DataModelFactory.createDataModel(new UtilityProjectCreationDataModelProvider());
-// }
-
- @Override
- protected ImageDescriptor getDefaultPageImageDescriptor() {
- return JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER);
- }
-
- @Override
- protected IFacetedProjectTemplate getTemplate() {
- return ProjectFacetsManager.getTemplate("jpt.jpa.template");
- }
-
- @Override
- protected IWizardPage createFirstPage() {
- return new NewJpaProjectFirstPage(model, "first.page"); //$NON-NLS-1$
- }
-
- @Override
- protected String getFinalPerspectiveID() {
- return "org.eclipse.jpt.ui.jpaPerspective";
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java
deleted file mode 100644
index 5dfd091bc4..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
-import java.util.*;
-
-public class AnnotatedEntityTemplate
-{
- protected static String nl;
- public static synchronized AnnotatedEntityTemplate create(String lineSeparator)
- {
- nl = lineSeparator;
- AnnotatedEntityTemplate result = new AnnotatedEntityTemplate();
- nl = null;
- return result;
- }
-
- public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "package ";
- protected final String TEXT_2 = ";";
- protected final String TEXT_3 = NL;
- protected final String TEXT_4 = NL + "import ";
- protected final String TEXT_5 = ";";
- protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: ";
- protected final String TEXT_7 = NL + " *" + NL + " */";
- protected final String TEXT_8 = NL;
- protected final String TEXT_9 = "(name=\"";
- protected final String TEXT_10 = "\")";
- protected final String TEXT_11 = NL + "@Table(name=\"";
- protected final String TEXT_12 = "\")";
- protected final String TEXT_13 = NL;
- protected final String TEXT_14 = NL + "@IdClass(";
- protected final String TEXT_15 = ".class)";
- protected final String TEXT_16 = NL + "public class ";
- protected final String TEXT_17 = " extends ";
- protected final String TEXT_18 = " implements ";
- protected final String TEXT_19 = ", ";
- protected final String TEXT_20 = " {" + NL + "" + NL + "\t";
- protected final String TEXT_21 = " " + NL + "\t@Id";
- protected final String TEXT_22 = NL + "\tprivate ";
- protected final String TEXT_23 = " ";
- protected final String TEXT_24 = ";";
- protected final String TEXT_25 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic ";
- protected final String TEXT_26 = "() {" + NL + "\t\tsuper();" + NL + "\t}";
- protected final String TEXT_27 = " " + NL + "\t@Id ";
- protected final String TEXT_28 = " " + NL + "\tpublic ";
- protected final String TEXT_29 = " get";
- protected final String TEXT_30 = "() {" + NL + "\t\treturn this.";
- protected final String TEXT_31 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
- protected final String TEXT_32 = "(";
- protected final String TEXT_33 = " ";
- protected final String TEXT_34 = ") {" + NL + "\t\tthis.";
- protected final String TEXT_35 = " = ";
- protected final String TEXT_36 = ";" + NL + "\t}";
- protected final String TEXT_37 = NL + " " + NL + "}";
- protected final String TEXT_38 = NL;
-
- public String generate(Object argument)
- {
- final StringBuffer stringBuffer = new StringBuffer();
- CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
-if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
- stringBuffer.append(TEXT_1);
- stringBuffer.append(model.getJavaPackageName());
- stringBuffer.append(TEXT_2);
- }
- stringBuffer.append(TEXT_3);
- Collection<String> imports = model.getImports(false);
-for (String anImport : imports) {
- stringBuffer.append(TEXT_4);
- stringBuffer.append(anImport);
- stringBuffer.append(TEXT_5);
- }
- stringBuffer.append(TEXT_6);
- stringBuffer.append(model.getEntityName());
- stringBuffer.append(TEXT_7);
- stringBuffer.append(TEXT_8);
- stringBuffer.append(model.getArtifactType());
- String ENTITY_NAME = model.getEntityName();
-if (model.isEntityNameSet()) {
- stringBuffer.append(TEXT_9);
- stringBuffer.append(ENTITY_NAME);
- stringBuffer.append(TEXT_10);
- }
- if (model.isTableNameSet()) {
- stringBuffer.append(TEXT_11);
- stringBuffer.append(model.getTableName());
- stringBuffer.append(TEXT_12);
- }
- stringBuffer.append(TEXT_13);
- stringBuffer.append(model.getInheritanceStrategy());
- if (model.isCompositePK()) {
- stringBuffer.append(TEXT_14);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_15);
- }
- stringBuffer.append(TEXT_16);
- stringBuffer.append(model.getClassName());
- String superClass = model.getSuperclassName();
- if (! "".equals(superClass)) {
- stringBuffer.append(TEXT_17);
- stringBuffer.append(superClass);
- }
-
- List<String> interfaces = model.getInterfaces();
- if (interfaces.size()>0) {
- stringBuffer.append(TEXT_18);
- }
- for (int i=0; i<interfaces.size(); i++) {
- String INTERFACE = (String) interfaces.get(i);
- if (i>0) {
- stringBuffer.append(TEXT_19);
- }
- stringBuffer.append(INTERFACE);
- }
- stringBuffer.append(TEXT_20);
- List<EntityRow> fields = model.getEntityFields();
- List<String> pkFields = model.getPKFields();
- for (EntityRow entity : fields) {
- String NAME = entity.getName();
- if (pkFields.contains(NAME) && model.isFieldAccess()) {
-
- stringBuffer.append(TEXT_21);
- }
- stringBuffer.append(TEXT_22);
- stringBuffer.append(entity.getType());
- stringBuffer.append(TEXT_23);
- stringBuffer.append(entity.getName());
- stringBuffer.append(TEXT_24);
- }
- stringBuffer.append(TEXT_25);
- stringBuffer.append(model.getClassName());
- stringBuffer.append(TEXT_26);
-
- fields = model.getEntityFields();
- if (fields != null) for (int i=0; i<fields.size(); i++) {
- EntityRow field = (EntityRow) fields.get(i);
- String TYPE = field.getType();
- String NAME = field.getName();
- String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
- if (pkFields.contains(NAME) && !model.isFieldAccess()) {
-
- stringBuffer.append(TEXT_27);
- }
- stringBuffer.append(TEXT_28);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_29);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_30);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_31);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_32);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_33);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_34);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_35);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_36);
- }
- stringBuffer.append(TEXT_37);
- stringBuffer.append(TEXT_38);
- return stringBuffer.toString();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java
deleted file mode 100644
index 8fa052bc14..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008, 2009 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.jface.XmlMappingFileViewerFilter;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
-import org.eclipse.jpt.utility.internal.ArrayTools;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-import org.eclipse.jst.j2ee.internal.wizard.NewJavaClassWizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-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.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-import org.eclipse.ui.model.WorkbenchContentProvider;
-import org.eclipse.ui.model.WorkbenchLabelProvider;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-
-public class EntityClassWizardPage extends NewJavaClassWizardPage{
-
- private static final String JPA_FACET = JptCorePlugin.FACET_ID;
- private static final String META_INF = "META-INF";//$NON-NLS-1$
- private static final String EMPTY = "";//$NON-NLS-1$
- private static final char SLASH = '/';
- private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$
- private static final String TABLE_PER_CLASS = "TABLE_PER_CLASS";//$NON-NLS-1$
- private static final String JOINED = "JOINED";//$NON-NLS-1$
- private static final String[] INHERITANCE_STRATEGIES = new String[] {
- EMPTY,
- SINGLE_TABLE,
- TABLE_PER_CLASS,
- JOINED };
- private Combo inheritanceStrategyCombo;
- private Button entityButton;
- private Button mapedAsSuperclassButton;
- private Button inheritanceButton;
- private Label displayNameLabel;
- private Button xmlSupportButton;
- private boolean isFirstCheck = true;
- private Text ormXmlName;
- private Button browseButton;
-
- public EntityClassWizardPage(IDataModel model, String pageName,
- String pageDesc, String pageTitle, String moduleType) {
- super(model, pageName, pageDesc, pageTitle, moduleType);
- }
-
-
- @Override
- protected String[] getValidationPropertyNames() {
- return ArrayTools.addAll(
- super.getValidationPropertyNames(),
- new String[] {IEntityDataModelProperties.XML_NAME, IEntityDataModelProperties.XML_SUPPORT});
- }
-
- /* Create top level composite (class properties) and add the entity's specific inheritance group
- * @see org.eclipse.jst.j2ee.internal.wizard.NewJavaClassWizardPage#createTopLevelComposite(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = super.createTopLevelComposite(parent);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.NEW_JPA_ENTITY_ENTITY_CLASS);
-
- createInheritanceControl(composite);
- inheritanceButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean isChecked = inheritanceButton.getSelection();
- if (isChecked) {
- entityButton.setSelection(true);
- mapedAsSuperclassButton.setSelection(false);
- }
- inheritanceStrategyCombo.setEnabled(isChecked);
- model.setBooleanProperty(IEntityDataModelProperties.ENTITY, true);
- model.setBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS, false);
- entityButton.setEnabled(!isChecked);
- mapedAsSuperclassButton.setEnabled(!isChecked);
- }
- });
- createXMLstorageControl(composite);
- xmlSupportButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean isChecked = xmlSupportButton.getSelection();
- enableMappingXMLChooseGroup(isChecked);
- if (isFirstCheck) {
- ormXmlName.setText(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH);
- isFirstCheck = false;
- }
- }
- });
- return composite;
- }
-
- /**
- * Create the inheritance group
- * @param parent the main composite
- */
- private void createInheritanceControl(Composite parent) {
- Group group = createGroup(parent, EntityWizardMsg.INHERITANCE_GROUP);
- entityButton = createRadioButton(group, EntityWizardMsg.ENTITY, IEntityDataModelProperties.ENTITY);
- mapedAsSuperclassButton = createRadioButton(group, EntityWizardMsg.MAPPED_AS_SUPERCLASS, IEntityDataModelProperties.MAPPED_AS_SUPERCLASS);
- inheritanceButton = createCheckButton(group, GridData.HORIZONTAL_ALIGN_FILL, 1/*horizontal span*/, EntityWizardMsg.INHERITANCE_CHECK_BOX, IEntityDataModelProperties.INHERITANCE);
- createComboBox(group, IEntityDataModelProperties.INHERITANCE_STRATEGY);
- }
-
- /**
- * Create the group, which manage entity mapping registration
- * @param parent the main composite
- */
- private void createXMLstorageControl(Composite parent) {
- Group group = createGroup(parent, EntityWizardMsg.XML_STORAGE_GROUP);
- xmlSupportButton = createCheckButton(group, GridData.FILL_HORIZONTAL, 3/*horizontal span*/, EntityWizardMsg.XML_SUPPORT, IEntityDataModelProperties.XML_SUPPORT);
- createBrowseGroup(group, EntityWizardMsg.CHOOSE_XML, IEntityDataModelProperties.XML_NAME);
- ormXmlName.setEnabled(false);
- browseButton.setEnabled(false);
- }
-
- /**
- * @param parent the main composite
- * @param text the name/title of the group
- * @return the created group
- */
- private Group createGroup(Composite parent, String text) {
- Group group = new Group(parent, SWT.NONE);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 3;
- group.setLayoutData(groupGridData);
- group.setLayout(new GridLayout(3, false));
- group.setText(text);
- return group;
- }
-
- /**
- * Create radio button
- * @param parent the main composite - inheritance group
- * @param text the label of the button
- * @param property the related property to which this button will be synchronized
- * @return the created button
- */
- private Button createRadioButton(Composite parent, String text, String property) {
- Button button = new Button(parent, SWT.RADIO);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 3;
- button.setLayoutData(groupGridData);
- button.setText(text);
- synchHelper.synchRadio(button, property, /*dependentControls*/ null);
- return button;
- }
-
- /**
- * Create check button
- * @param parent the main composite - inheritance group
- * @param text the label of the button
- * @param property the related property to which this button will be synchronized
- * @return the created button
- */
- private Button createCheckButton(Composite parent, int fillStrategy, int horizontalSpan, String text, String property) {
- final Button button = new Button(parent, SWT.CHECK);
- GridData groupGridData = new GridData(fillStrategy);
- groupGridData.horizontalSpan = horizontalSpan;
- button.setLayoutData(groupGridData);
- button.setText(text);
- synchHelper.synchCheckbox(button, property, /*dependentControls*/ null);
- return button;
- }
-
- /**
- * Create combo box, which presents the set of possible inheritance strategies
- * @param parent the main composite - inheritance group
- * @param property the related property to which this button will be synchronized
- * @return
- */
- private Combo createComboBox(Composite parent, String property) {
- inheritanceStrategyCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 2;
- inheritanceStrategyCombo.setLayoutData(groupGridData);
- inheritanceStrategyCombo.setItems(INHERITANCE_STRATEGIES);
- synchHelper.synchCombo(inheritanceStrategyCombo, property, /*dependentControls*/ null);
- inheritanceStrategyCombo.setEnabled(false);
- return inheritanceStrategyCombo;
-
- }
-
- /**
- * Create XML group
- * @param parent the main composite
- * @param label the name of the group
- * @param property the related property to which this group will be synchronized
- * @return the created group
- */
- private void createBrowseGroup(Composite parent, String label, String property) {
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setLayout(new GridLayout(3, false));
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- displayNameLabel = new Label(composite, SWT.LEFT);
- displayNameLabel.setText(label);
- displayNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
- ormXmlName = new Text(composite, SWT.SINGLE | SWT.BORDER);
- ormXmlName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- browseButton = new Button(composite, SWT.PUSH);
- browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL);
- GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- browseButtonData.horizontalSpan = 1;
- browseButton.setLayoutData(browseButtonData);
- browseButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- handleChooseXmlButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- // Do nothing
- }
- });
- synchHelper.synchText(ormXmlName, property, /*dependentControls*/null);
-
- enableMappingXMLChooseGroup(false);
- }
-
- /**
- * Process browsing when the Browse... button have been pressed. Allow choosing of
- * XML for entity mapping registration
- *
- */
- private void handleChooseXmlButtonPressed() {
- IProject project = (IProject) getDataModel().getProperty(INewJavaClassDataModelProperties.PROJECT);
- if (project == null) {
- return;
- }
- JpaProject jpaProject = JptCorePlugin.getJpaProject(project);
- ViewerFilter filter = getDialogViewerFilter(jpaProject);
- ITreeContentProvider contentProvider = new WorkbenchContentProvider();
- ILabelProvider labelProvider = new WorkbenchLabelProvider();
- SelectMappingXMLDialog dialog = new SelectMappingXMLDialog(getShell(), labelProvider, contentProvider);
- dialog.setTitle(EntityWizardMsg.MAPPING_XML_TITLE);
- dialog.setMessage(EntityWizardMsg.CHOOSE_MAPPING_XML_MESSAGE);
- dialog.addFilter(filter);
-
- String ormFileName = this.ormXmlName.getText();
- JpaXmlResource resource = jpaProject.getMappingFileXmlResource(ormFileName);
- IFile initialSelection = (resource != null) ? resource.getFile() : null;
- dialog.setInput(project);
-
- if (initialSelection != null) {
- dialog.setInitialSelection(initialSelection);
- }
- if (dialog.open() == Window.OK) {
- this.ormXmlName.setText(dialog.getChosenName());
- this.model.validateProperty(IEntityDataModelProperties.XML_NAME);
- }
- }
-
- /**
- * This method create filter for the browse/add alternative mapping XML
- * @return new instance of viewer filter for the SelectMappingXMLDialog
- */
- protected ViewerFilter getDialogViewerFilter(JpaProject jpaProject) {
- return new XmlMappingFileViewerFilter(jpaProject);
- }
-
- private void enableMappingXMLChooseGroup(boolean enabled) {
- displayNameLabel.setEnabled(enabled);
- ormXmlName.setEnabled(enabled);
- browseButton.setEnabled(enabled);
-
- }
-
- /**
- * This method is used by the project list initializer. The method checks
- * if the specified project is valid to include it in the project list.
- *
- * <p>Subclasses of this wizard page should override this method to
- * adjust filtering of the projects to their needs. </p>
- *
- * @param project reference to the project to be checked
- *
- * @return <code>true</code> if the project is valid to be included in
- * the project list, <code>false</code> - otherwise.
- */
- @Override
- protected boolean isProjectValid(IProject project) {
- IProjectFacet jpaFacet = ProjectFacetsManager.getProjectFacet(JPA_FACET);
- IFacetedProject fProject = null;
- try {
- fProject = ProjectFacetsManager.create(project);
- } catch (CoreException e) {
- return false;
- }
- return (project.isAccessible() && fProject != null && fProject.hasProjectFacet(jpaFacet));
- }
-
- private class SelectMappingXMLDialog extends ElementTreeSelectionDialog
- {
- private String xmlName = EMPTY;
-
-
- public SelectMappingXMLDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
- super(parent, labelProvider, contentProvider);
- }
-
-
- /**
- * @return the name of the alternative mapping XML
- */
- public String getChosenName() {
- String result = EMPTY;
- Object element = getFirstResult();
- if (element instanceof IContainer) {
- IContainer container = (IContainer) element;
- result = container.getFullPath().toString() + File.separatorChar + xmlName;
- } else {
- IFile f = (IFile) element;
- result = f.getFullPath().toOSString();
- }
- result = removeRedundantSegmentFromName(result);
- return result;
- }
-
- @Override
- /*
- * @see ElementTreeSelectionDialog#updateOKStatus(Composite)
- */
- protected void updateOKStatus() {
- super.updateOKStatus();
- TreeSelection selection = (TreeSelection)getTreeViewer().getSelection();
- IResource selectedResource = (IResource) selection.getFirstElement();
- if (selectedResource instanceof IFile) {
- updateStatus(new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""));
- }
- else {
- updateStatus(new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""));
- }
- }
-
- /**
- * This method is for internal purposes only
- * @param input non formated path to the mapping XML
- * @return the formated path to the mapping XML
- */
- private String removeRedundantSegmentFromName(String input) {
- String output = input.substring(input.indexOf(META_INF));
- output = output.replace(File.separatorChar, SLASH);
- return output;
- }
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java
deleted file mode 100644
index 7e3b15e77e..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
-import org.eclipse.swt.SWT;
-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.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
-import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
-
-public class EntityFieldsWizardPage extends DataModelWizardPage {
-
- private Text entityNameText;
- private Text tableNameText;
- private Button tableNameCheckButton;
- private Button fieldAccessButton;
- private Button propertyAccessButton;
- private boolean isNonEntity = true;
- private boolean isButtonsCreated = false;
-
- public EntityFieldsWizardPage(IDataModel model, String pageName) {
- super(model, pageName);
- setDescription(EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_DESCRIPTION);
- this.setTitle(EntityWizardMsg.ENTITY_PROPERTIES_TITLE);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jem.util.ui.wizard.WTPWizardPage#getValidationPropertyNames()
- */
- @Override
- protected String[] getValidationPropertyNames() {
- return new String[]{IEntityDataModelProperties.ENTITY_FIELDS,
- IEntityDataModelProperties.PK_FIELDS};
- }
-
- /* Create the main composite and add to it the entity properties
- * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#createTopLevelComposite(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setLayout(new GridLayout());
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.NEW_JPA_ENTITY_ENTITY_PROPERTIES);
-
- GridData data = new GridData(GridData.FILL_BOTH);
- data.widthHint = 300;
- data.heightHint = 450;
- composite.setLayoutData(data);
- composite.pack();
-
- entityNameText = createNameGroup(composite, EntityWizardMsg.ENTITY_NAME, IEntityDataModelProperties.ENTITY_NAME);
- Group group = createGroup(composite, EntityWizardMsg.TABLE_NAME_GROUP);
- tableNameCheckButton= createCheckButton(group, EntityWizardMsg.USE_DEFAULT, IEntityDataModelProperties.TABLE_NAME_DEFAULT);
- tableNameText = createNameGroup(group, EntityWizardMsg.TABLE_NAME, IEntityDataModelProperties.TABLE_NAME);
- tableNameText.setEnabled(!tableNameCheckButton.getSelection());
- isButtonsCreated = true;
- initNameGroup();
- createEntityFieldsGroup(composite);
-
- Group accessTypeGroup = createGroup(composite, EntityWizardMsg.ACCESS_TYPE);
- fieldAccessButton = createRadioButton(accessTypeGroup, EntityWizardMsg.FIELD_BASED, IEntityDataModelProperties.FIELD_ACCESS_TYPE);
- propertyAccessButton = createRadioButton(accessTypeGroup, EntityWizardMsg.PROPERTY_BASED, IEntityDataModelProperties.PROPERTY_ACCESS_TYPE);
-
-
- IStatus projectStatus = validateProjectName();
- if (!projectStatus.isOK()) {
- setErrorMessage(projectStatus.getMessage());
- composite.setEnabled(false);
- }
- Dialog.applyDialogFont(parent);
- return composite;
- }
-
- /**
- * @return the status of the project name correctness
- */
- protected IStatus validateProjectName() {
- // check for empty
- if (model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME) == null || model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME).trim().length() == 0) {
- return WTPCommonPlugin.createErrorStatus(EntityWizardMsg.NO_JPA_PROJECTS);
- }
- return WTPCommonPlugin.OK_STATUS;
- }
-
- protected void createEntityFieldsGroup(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- GridData groupGridData = new GridData(GridData.FILL_BOTH);
- groupGridData.horizontalSpan = 3;
- group.setLayoutData(groupGridData);
- group.setLayout(new GridLayout(3, false));
- group.setText(EntityWizardMsg.ENTITY_FIELDS_GROUP);
- new EntityRowTableWizardSection(group, model, IEntityDataModelProperties.ENTITY_FIELDS);
- }
-
- /**
- * Create named group
- * @param parent the main composite
- * @param label the name of the group
- * @param property the related property to which this group will be synchronized
- * @return the created group
- */
- protected Text createNameGroup(Composite parent, String label, String property) {
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setLayout(new GridLayout(3, false));
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- Label displayNameLabel = new Label(composite, SWT.LEFT);
- displayNameLabel.setText(label);
- displayNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
- Text nameText = new Text(composite, SWT.SINGLE | SWT.BORDER);
- nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- synchHelper.synchText(nameText, property, /*dependentControls*/null);
- return nameText;
- }
-
- /**
- * Create group
- * @param parent the main composite
- * @param text the name of the group
- * @return the created group
- */
- private Group createGroup(Composite parent, String text) {
- Group group = new Group(parent, SWT.NONE);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 3;
- group.setLayoutData(groupGridData);
- group.setLayout(new GridLayout(3, false));
- group.setText(text);
- return group;
- }
-
- /**
- * Create check button
- * @param parent the main composite - inheritance group
- * @param text the label of the button
- * @param property the related property to which this button will be synchronized
- * @return the created button
- */
- private Button createCheckButton(Composite parent, String text, String property) {
- final Button button = new Button(parent, SWT.CHECK);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 3;
- button.setLayoutData(groupGridData);
- button.setText(text);
- button.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean isChecked = button.getSelection();
- if (tableNameText != null) {
- tableNameText.setEnabled(!isChecked);
- }
- }
- });
- synchHelper.synchCheckbox(button, property, /*dependentControls*/ null);
- return button;
- }
-
- /**
- * Create radio button
- * @param parent the main composite - inheritance group
- * @param text the label of the button
- * @param property the related property to which this button will be synchronized
- * @return the created button
- */
- private Button createRadioButton(Composite parent, String text, String property) {
- Button button = new Button(parent, SWT.RADIO);
- GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL);
- groupGridData.horizontalSpan = 3;
- button.setLayoutData(groupGridData);
- button.setText(text);
- synchHelper.synchRadio(button, property, /*dependentControls*/ null);
- return button;
- }
-
- /*
- * If a property changes that we want to validate, force validation on this page.
- *
- * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelListener#propertyChanged(java.lang.String,
- * java.lang.Object, java.lang.Object)
- */
- @Override
- public void propertyChanged(DataModelEvent event) {
- String propertyName = event.getPropertyName();
- if (IEntityDataModelProperties.MAPPED_AS_SUPERCLASS.equals(propertyName)) {
- initNameGroup();
- }
- super.propertyChanged(event);
- }
-
- /**
- * The methods is for the internal use only. It will set the entity and table name
- * group to be disabled if the created artifact is not entity
- */
- private void initNameGroup() {
- isNonEntity = model.getBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS);
- if (isButtonsCreated) {
- entityNameText.setEnabled(!isNonEntity);
- tableNameCheckButton.setEnabled(!isNonEntity);
- tableNameText.setEnabled(!tableNameCheckButton.getSelection());
- }
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
-
-
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java
deleted file mode 100644
index 79a12ac634..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java
+++ /dev/null
@@ -1,822 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.jdt.ui.IJavaElementSearchConstants;
-import org.eclipse.jdt.ui.JavaUI;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.IJavaSearchScope;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.fieldassist.ContentProposalAdapter;
-import org.eclipse.jface.fieldassist.IContentProposalProvider;
-import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
-import org.eclipse.jface.fieldassist.TextContentAdapter;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-import org.eclipse.jst.j2ee.internal.dialogs.TypeSearchEngine;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-
-/**
- * The class presents the table with entity fields. In the java file are included also content
- * and label provider, add and edit entity dialogs as well as help internal objects - listener
- * and callback from the dialog to the main composite (table).
- *
- */
-public class EntityRowTableWizardSection extends Composite {
-
- /**
- * The possible entity types, mentioned in the specification (Chapter 2.1.1 Persistent Fields and Properties p.20)
- */
- protected final static String[] VALID_TYPES = {"int",
- "long",
- "short",
- "char",
- "boolean",
- "byte",
- "double",
- "float",
- "java.lang.String",
- "java.lang.Integer",
- "java.lang.Long",
- "java.lang.Short",
- "java.lang.Character",
- "java.lang.Boolean",
- "java.lang.Byte",
- "java.lang.Double",
- "java.lang.Float",
- "java.math.BigDecimal",
- "java.math.BigInteger",
- "java.util.Date",
- "java.util.Calendar",
- "java.sql.Date",
- "java.sql.Time",
- "java.sql.Timestamp",
- "String",
- "Integer",
- "Long",
- "Short",
- "Character",
- "Boolean",
- "Byte",
- "Double",
- "Float" };
-
- private CheckboxTableViewer mTableViewer = null;
- private Table mTableWidget = null;
- private final int NAME_COLUMN = 1;
- private final int TYPE_COLUMN = 2;
-
-
-
-
- private Button addButton;
- private Button editButton;
- private Button removeButton;
- private String title = EntityWizardMsg.ENTITY_FIELDS_DIALOG_TITLE;
- private String[] typeProposals = VALID_TYPES;
- private String[] labelsForText = new String[]{EntityWizardMsg.TYPE_TEXT_FIELD, EntityWizardMsg.NAME_TEXT_FIELD};
- private IDataModel model;
- private String propertyName;
- private Image labelProviderImage = null;
- private DialogCallback callback;
- private static KeyStroke ks = null;
- static {
- try {
- ks = KeyStroke.getInstance("Ctrl+Space");
- } catch (ParseException e1) {
- JptUiPlugin.log(e1);
- }
- }
-
-
- /**
- * @param parent the main composite - Entity fields page
- * @param model the data model representation
- * @param propertyName data property name
- */
- public EntityRowTableWizardSection(Composite parent, IDataModel model, String propertyName) {
- super(parent, SWT.NONE);
- this.model = model;
- this.propertyName = propertyName;
-
- GridLayout layout = new GridLayout(2, false);
- layout.marginHeight = 4;
- layout.marginWidth = 0;
- this.setLayout(layout);
- this.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- mTableWidget = new Table(this, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);
- mTableWidget.setHeaderVisible(true);
- mTableWidget.setLinesVisible(true);
-
- mTableViewer = new CheckboxTableViewer(mTableWidget);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.verticalSpan = 2;
- mTableWidget.setLayoutData(data);
- mTableViewer.setContentProvider(new EntityRowContentProvider());
- mTableViewer.setLabelProvider(new EntityRowLabelProvider());
-
- final Composite buttonComposition = new Composite(this, SWT.NULL);
- layout = new GridLayout();
- layout.marginHeight = 0;
- buttonComposition.setLayout(layout);
- buttonComposition.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.VERTICAL_ALIGN_BEGINNING));
-
- addButton = new Button(buttonComposition, SWT.PUSH);
- addButton.setText(EntityWizardMsg.ADD_BUTTON_LABEL);
- addButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL));
- addButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent event) {
- handleAddButtonSelected();
- }
- public void widgetDefaultSelected(SelectionEvent event) {
- //Do nothing
- }
- });
-
- editButton = new Button(buttonComposition, SWT.PUSH);
- editButton.setText(EntityWizardMsg.EDIT_BUTTON_LABEL);
- editButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL));
- editButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent event) {
- handleEditButtonSelected();
- }
- public void widgetDefaultSelected(SelectionEvent event) {
- //Do nothing
- }
- });
- editButton.setEnabled(false);
- mTableViewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
- handleEditButtonSelected();
- }
- });
-
- removeButton = new Button(buttonComposition, SWT.PUSH);
- removeButton.setText(EntityWizardMsg.REMOVE_BUTTON_LABEL);
- removeButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL));
- removeButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent event) {
- handleRemoveButtonSelected();
- }
- public void widgetDefaultSelected(SelectionEvent event) {
- //Do nothing
- }
- });
- removeButton.setEnabled(false);
-
- mTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection selection = event.getSelection();
- if (editButton != null) {
- boolean enabled = ((IStructuredSelection) selection).size() == 1;
- editButton.setEnabled(enabled);
- }
- removeButton.setEnabled(!selection.isEmpty());
- }
- });
-
-
- final TableColumn pkColumn = new TableColumn(mTableWidget, SWT.CHECK);
- pkColumn.setText(EntityWizardMsg.KEY);
- pkColumn.pack();
- pkColumn.setResizable(false);
-
- TableColumn nameColumn = new TableColumn(mTableWidget, SWT.NONE);
- nameColumn.setText(EntityWizardMsg.NAME_COLUMN);
-
- TableColumn typeColumn = new TableColumn(mTableWidget, SWT.NONE);
- typeColumn.setText(EntityWizardMsg.TYPE_COLUMN);
-
- this.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- Table table = mTableViewer.getTable();
- TableColumn[] columns = table.getColumns();
- Point buttonArea = buttonComposition.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- Rectangle area = table.getParent().getClientArea();
- Point preferredSize = mTableViewer.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
- int width = area.width - 2 * table.getBorderWidth()- buttonArea.x - columns.length * 2 - pkColumn.getWidth();
- if (preferredSize.y > area.height + table.getHeaderHeight()) {
- // Subtract the scrollbar width from the total column width
- // if a vertical scrollbar will be required
- Point vBarSize = table.getVerticalBar().getSize();
- width -= vBarSize.x;
- }
- Point oldSize = table.getSize();
- int consumeWidth = 0;
- int col = columns.length - 1;
- for (int i = 1; i < columns.length; i++) {
- if (oldSize.x > area.width) {
- // table is getting smaller so make the columns
- // smaller first and then resize the table to
- // match the client area width
- consumeWidth = setColumntWidth(width, columns, consumeWidth, i);
- table.setSize(area.width - buttonArea.x - (col * 2 + pkColumn.getWidth()), area.height);
- } else {
- // table is getting bigger so make the table
- // bigger first and then make the columns wider
- // to match the client area width
- consumeWidth = setColumntWidth(width, columns, consumeWidth, i);
- table.setSize(area.width - buttonArea.x - (col * 2 + pkColumn.getWidth()), area.height);
- }
- }
- }
-
- private int setColumntWidth(int width, TableColumn[] columns,
- int consumeWidth, int i) {
- if (i < columns.length - 1) {
- columns[i].setWidth(width / (columns.length - 1));
- consumeWidth += columns[i].getWidth();
- } else {
- columns[i].setWidth(width - consumeWidth);
- }
- return consumeWidth;
- }
- });
-
- mTableViewer.addCheckStateListener(new PKFieldCheckStateListener());
- callback = new FieldDialogCallback();
- }
-
- /**
- * This method process the Add... button pressed event. It opens dialog to
- * add new entity field
- */
- private void handleAddButtonSelected() {
- AddFieldDialog dialog = new AddFieldDialog(getShell(), title, typeProposals, labelsForText);
- int result = dialog.open();
- if (result == Window.CANCEL) {
- return;
- }
- EntityRow entityRow = dialog.getEntityRow();
- addEntityRow(entityRow);
- }
-
- /**
- * Add new entity to the table input
- *
- * @param entity
- * the entity which have to be added to the table
- */
- private void addEntityRow(EntityRow entity) {
- if (entity == null)
- return;
- List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput();
- if (valueList == null)
- valueList = new ArrayList<EntityRow>();
- valueList.add(entity);
- setInput(valueList);
- }
-
- /**
- * This method process the Edit... button pressed event. It opens dialog to edit chosen entity field
- */
- private void handleEditButtonSelected() {
- ISelection s = mTableViewer.getSelection();
- if (!(s instanceof IStructuredSelection))
- return;
- IStructuredSelection selection = (IStructuredSelection) s;
- if (selection.size() != 1)
- return;
-
- Object selectedObj = selection.getFirstElement();
- EntityRow entityForEdit = (EntityRow) selectedObj;
- int index = mTableWidget.getSelectionIndex();
- boolean isChecked = mTableViewer.getChecked(entityForEdit);
-
- EditFieldDialog dialog = new EditFieldDialog(getShell(), title, typeProposals, labelsForText, entityForEdit);
- dialog.open();
- EntityRow entityRow = dialog.getEntityRow();
- if (entityRow != null) {
- editEntityRow(index, entityRow);
- mTableViewer.setChecked(entityRow, isChecked);
- mTableViewer.setGrayed(entityRow, false);
- }
- }
-
- /**
- * Edit chosen entity from the table
- * @param index the index of the entity in the table
- * @param newEntity the edited entity field
- */
- private void editEntityRow(int index, EntityRow newEntity) {
- if (newEntity == null)
- return;
-
- List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput();
- if (valueList == null) {
- valueList = new ArrayList();
- }
-
- if (index == -1) {
- valueList.add(newEntity);
- } else {
- valueList.set(index, newEntity);
- }
-
- setInput(valueList);
- }
-
- /**
- * This method process the Remove button pressed event.
- */
- private void handleRemoveButtonSelected() {
- ISelection selection = mTableViewer.getSelection();
- if (selection.isEmpty() || !(selection instanceof IStructuredSelection))
- return;
- List selectedObject = ((IStructuredSelection) selection).toList();
- removeEntityRow(selectedObject);
- }
-
- /**
- * Removes the selected entities from the table
- * @param entities list with entities, which should be removed
- */
- private void removeEntityRow(Collection entities) {
- List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput();
- valueList.removeAll(entities);
- setInput(valueList);
- }
-
- /**
- * Set the input of the table
- * @param input the list with entities which have to be presented in the table
- */
- private void setInput(List input) {
- mTableViewer.setInput(input);
- // Create a new list to trigger property change
- ArrayList<EntityRow> newInput = new ArrayList<EntityRow>();
- newInput.addAll(input);
- model.setProperty(propertyName, newInput);
- }
-
- /**
- * @return the TableViewer of the table
- */
- public TableViewer getTableViewer() {
- return mTableViewer;
- }
-
- // PROVIDERS FOR THE FIELD TABLE
-
- /**
- * The content provider for the table items
- */
- protected class EntityRowContentProvider implements IStructuredContentProvider {
- public boolean isDeleted(Object element) {
- return false;
- }
- public Object[] getElements(Object element) {
- if (element instanceof List) {
- return ((List) element).toArray();
- }
- return new Object[0];
- }
- public void inputChanged(Viewer aViewer, Object oldInput, Object newInput) {
- //Default nothing
- }
- public void dispose() {
- //Default nothing
- }
- }
-
- /**
- * The label provider for the table items
- */
- protected class EntityRowLabelProvider extends LabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex) {
- if (columnIndex == 0) {
- return labelProviderImage;
- }
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- EntityRow entity = (EntityRow) element;
- if (columnIndex == NAME_COLUMN) {
- return entity.getName();
- }
- if (columnIndex == TYPE_COLUMN) {
- return entity.getFqnTypeName();
- }
- mTableViewer.setChecked(entity, entity.isKey());
- return "";
- }
-
- @Override
- public Image getImage(Object element) {
- return labelProviderImage;
- }
-
- @Override
- public String getText(Object element) {
- String[] array = (String[]) element;
- if (array.length > 0) {
- return array[0];
- } else {
- return super.getText(element);
- }
- }
- }
- // END - PROVIDERS FOR THE FIELD TABLE
-
- /**
- * Listener for the Primary Key check box in the table item
- */
- private class PKFieldCheckStateListener implements ICheckStateListener {
-
- public void checkStateChanged(CheckStateChangedEvent event) {
- List<String> pkFields = new ArrayList<String>();
- TableItem[] children = mTableViewer.getTable().getItems();
- for (int i = 0; i < children.length; i++) {
- TableItem item = children[i];
- EntityRow entityRow = (EntityRow)item.getData();
- entityRow.setKey(item.getChecked());
- if (item.getChecked())
- pkFields.add(entityRow.getName());
- }
- model.setProperty(IEntityDataModelProperties.PK_FIELDS, pkFields);
- }
-
- }
-
- // CALLBACK MECHANISM
- /**
- * Callback interface used by the Add/Edit-FieldDialog classes.
- */
- public interface DialogCallback {
-
- /**
- * Validates the text fields.
- * <p>Used to decide whether to enable the OK button of the dialog.
- * If the method returns <code>true</code> the OK button is enabled,
- * otherwise the OK button is disabled.</p>
- * @param combo contains the predefined types
- * @param texts the name of the entity field
- * @return <code>true</code> if the values in the text fields are
- * valid, <code>false</code> otherwise.
- */
- public boolean validate(Text type, Text[] texts);
-
- /**
- * Retrieves the entity presentation object from the fields of the dialog.
- * <p>Implementers of the callback can use these method to do some
- * preprocessing (like trimming) of the data in the text fields before
- * using it. The returned values will be the actual data that will be
- * put in the table viewer.</p>
- * @param combo contains the predefined types
- * @param texts the name of the entity field
- * @return the entity presentation object retrieved from the dialog
- */
- public EntityRow retrieveResultStrings(Text type, Text[] texts);
-
- }
-
- /**
- * Implementation of the <code>FieldDialogCallback</code> interface for
- * both "Name" and "Types" table columns.
- */
- public class FieldDialogCallback implements DialogCallback {
-
- /**
- * The first text field should not be empty.
- */
- public boolean validate(Text type, Text[] texts) {
- if (texts.length > 0) {
- IStatus validateFieldNameStatus = JavaConventions
- .validateFieldName(texts[0].getText(),
- JavaCore.VERSION_1_5,
- JavaCore.VERSION_1_5);
- if (!validateFieldNameStatus.isOK()) {
- return false;
- }
- }
- if (type.getText().equals("")) {
- return false;
- }
- return true;
- }
-
- /**
- * Just retrieves the unmodified values of the text fields as a
- * entity field presentation
- * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow
- */
- public EntityRow retrieveResultStrings(Text type, Text[] texts) {
- EntityRow entity = new EntityRow();
- entity.setFqnTypeName(type.getText());
- entity.setName(texts[0].getText());
- return entity;
- }
- }
-
- // THE DIALOGS USED FOR ADD/EDIT OF ENTITY FIELDS - BEGIN
-
- /**
- * The dialog which collect the information (name and type) for the new entity field
- */
- private class AddFieldDialog extends Dialog implements ModifyListener, SelectionListener {
- protected String windowTitle;
- protected String[] typeProposals;
- protected String[] labelsForText;
- protected Text[] texts;
- protected EntityRow entityRow;
- protected Text attributeType;
- protected ContentProposalAdapter contentProposalAdapter;
-
- /**
- * Constructs AddFieldDialog
- * @param shell
- * @param windowTitle dialog label
- * @param typeProposals the elements for the combo
- * @param labelsForText name text
- */
- public AddFieldDialog(Shell shell, String windowTitle, String[] typeProposals, String[] labelsForText) {
- super(shell);
- this.windowTitle = windowTitle;
- this.typeProposals = typeProposals;
- this.labelsForText = labelsForText;
- }
-
- /* Create the area of dialog
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
- @Override
- public Control createDialogArea(Composite parent) {
-
- Composite composite = (Composite) super.createDialogArea(parent);
- getShell().setText(windowTitle);
-
- GridLayout layout = new GridLayout();
- layout.numColumns = 4;
- composite.setLayout(layout);
- GridData data = new GridData();
- data.verticalAlignment = GridData.FILL;
- data.horizontalAlignment = GridData.FILL;
- data.widthHint = 300;
- composite.setLayoutData(data);
-
- Label label = new Label(composite, SWT.LEFT);
- label.setText(labelsForText[0]);
- label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
-
-
- attributeType = new Text(composite, SWT.SINGLE | SWT.BORDER);// | SWT.READ_ONLY);
- //combo.setItems(labelsForCombo);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 2;
- attributeType.setLayoutData(data);
-
- Button browseButton = new Button(composite, SWT.PUSH);
- browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL);
- GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- browseButtonData.horizontalSpan = 1;
- browseButton.setLayoutData(browseButtonData);
- browseButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- handleChooseEntityTypeButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- // Do nothing
- }
- });
-
- int n = labelsForText.length;
- texts = new Text[n-1];
- for (int i = 1; i < n; i++) {
- Label labelI = new Label(composite, SWT.LEFT);
- labelI.setText(labelsForText[i]);
- labelI.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
- texts[i-1] = new Text(composite, SWT.SINGLE | SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 2;
- texts[i-1].setLayoutData(data);
- }
-
- attributeType.setFocus();
- Dialog.applyDialogFont(parent);
- createContentProposalProvider();
- return composite;
- }
-
- private IContentProposalProvider createContentProposalProvider() {
- SimpleContentProposalProvider contProvider = new SimpleContentProposalProvider(typeProposals);
- contProvider.setFiltering(true);
-
- contentProposalAdapter = new ContentProposalAdapter(
- attributeType,
- new TextContentAdapter(),
- contProvider,
- ks,
- new char[] {'b', 'c', 'd', 'i', 'f', 'l', 's', 'j', 'B', 'C', 'D', 'F', 'S', 'L', 'I'});
- contentProposalAdapter.setEnabled(true);
- contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
- return contProvider;
- }
-
-
- /**
- * Process browsing when the Browse... button have been pressed. Allow adding of entity field
- * with arbitrary type.
- */
- private void handleChooseEntityTypeButtonPressed() {
- //getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT));
- IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
- if (packRoot == null) {
- return;
- }
-
- // this eliminates the non-exported classpath entries
- final IJavaSearchScope scope = TypeSearchEngine.createJavaSearchScopeForAProject(packRoot.getJavaProject(), true, true);
-
- // This includes all entries on the classpath.
- SelectionDialog dialog=null;
- try{
- dialog = JavaUI
- .createTypeDialog(
- getShell(),
- null,
- scope,
- IJavaElementSearchConstants.CONSIDER_ALL_TYPES,
- false);
- } catch (JavaModelException e) {
- JptUiPlugin.instance().getLog().log(e.getStatus());
- return;
- }
-
- dialog.setTitle(EntityWizardMsg.TYPE_DIALOG_TITLE);
- dialog.setMessage(EntityWizardMsg.TYPE_DIALOG_DESCRIPTION);
-
- if (dialog.open() == Window.OK) {
- IType type;
- Object[] result = dialog.getResult();
- if (result == null || result.length == 0) {
- type = null;
- }
- else type = (IType) result[0];
- String superclassFullPath = IEntityDataModelProperties.EMPTY_STRING;
- if (type != null) {
- superclassFullPath = type.getFullyQualifiedName();
- }
- attributeType.setText(superclassFullPath);
- //getControl().setCursor(null);
- return;
- }
- //getControl().setCursor(null);
- }
-
-
- /* Create the content of the dialog
- * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Control createContents(Composite parent) {
- Composite composite = (Composite) super.createContents(parent);
-
- attributeType.addSelectionListener(this);
- attributeType.addModifyListener(this);
- for (int i = 0; i < texts.length; i++) {
- texts[i].addModifyListener(this);
- }
-
- updateOKButton();
-
- return composite;
- }
-
- /* Processes OK button pressed event.
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- */
- @Override
- protected void okPressed() {
- entityRow = callback.retrieveResultStrings(attributeType, texts);
- super.okPressed();
- }
-
- /**
- * @return the entity representation with the information collected from the dialog
- */
- public EntityRow getEntityRow() {
- return entityRow;
- }
-
- /* Processes text modifying event
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void modifyText(ModifyEvent e) {
- updateOKButton();
- }
-
- /**
- * Sets state of the OK button in accordance with validate method of the callback object
- * @see DialogCallback
- */
- private void updateOKButton() {
- getButton(IDialogConstants.OK_ID).setEnabled(callback.validate(attributeType, texts));
- }
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
-
- }
- /* Update OK button when the appropriate event occurs
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- updateOKButton();
- }
- }
-
- /**
- * Constructs EditFieldDialog
- */
- private class EditFieldDialog extends AddFieldDialog {
- protected EntityRow entityRow;
- /**
- * EditFieldDialog constructor comment.
- */
- public EditFieldDialog(Shell shell, String windowTitle, String[] labelsForCombo, String[] labelsForText, EntityRow entity) {
- super(shell, windowTitle, labelsForCombo, labelsForText);
- this.entityRow = entity;
- }
-
- /* Create the area of the dialog
- * @see org.eclipse.jpt.ui.internal.wizards.entity.EntityRowTableWizardSection.AddFieldDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
- @Override
- public Control createDialogArea(Composite parent) {
-
- Composite composite = (Composite) super.createDialogArea(parent);
-
- attributeType.setText(entityRow.getFqnTypeName());
- texts[0].setText(entityRow.getName());
-
- return composite;
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java
deleted file mode 100644
index a5309c4a95..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
-import java.util.*;
-
-public class EntityTemplate
-{
- protected static String nl;
- public static synchronized EntityTemplate create(String lineSeparator)
- {
- nl = lineSeparator;
- EntityTemplate result = new EntityTemplate();
- nl = null;
- return result;
- }
-
- public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "package ";
- protected final String TEXT_2 = ";";
- protected final String TEXT_3 = NL;
- protected final String TEXT_4 = NL + "import ";
- protected final String TEXT_5 = ";";
- protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: ";
- protected final String TEXT_7 = NL + " *" + NL + " */" + NL + "public class ";
- protected final String TEXT_8 = " extends ";
- protected final String TEXT_9 = " implements ";
- protected final String TEXT_10 = ", ";
- protected final String TEXT_11 = " {" + NL + "" + NL + "\t";
- protected final String TEXT_12 = " " + NL + "\tprivate ";
- protected final String TEXT_13 = " ";
- protected final String TEXT_14 = ";";
- protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;\t" + NL + "\tpublic ";
- protected final String TEXT_16 = "() {" + NL + "\t\tsuper();" + NL + "\t} " + NL + "\t";
- protected final String TEXT_17 = " " + NL + "\tpublic ";
- protected final String TEXT_18 = " get";
- protected final String TEXT_19 = "() {" + NL + " \t\treturn this.";
- protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
- protected final String TEXT_21 = "(";
- protected final String TEXT_22 = " ";
- protected final String TEXT_23 = ") {" + NL + "\t\tthis.";
- protected final String TEXT_24 = " = ";
- protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t";
- protected final String TEXT_26 = NL + " " + NL + "}";
- protected final String TEXT_27 = NL;
-
- public String generate(Object argument)
- {
- final StringBuffer stringBuffer = new StringBuffer();
- CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
-if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
- stringBuffer.append(TEXT_1);
- stringBuffer.append(model.getJavaPackageName());
- stringBuffer.append(TEXT_2);
- }
- stringBuffer.append(TEXT_3);
- Collection<String> imports = model.getImports(false);
-for (String anImport : imports) {
- stringBuffer.append(TEXT_4);
- stringBuffer.append(anImport);
- stringBuffer.append(TEXT_5);
- }
- stringBuffer.append(TEXT_6);
- stringBuffer.append(model.getEntityName());
- stringBuffer.append(TEXT_7);
- stringBuffer.append(model.getClassName());
- String superClass = model.getSuperclassName();
- if (! "".equals(superClass)) {
- stringBuffer.append(TEXT_8);
- stringBuffer.append(superClass);
- }
-
- List<String> interfaces = model.getInterfaces();
- if (interfaces.size()>0) {
- stringBuffer.append(TEXT_9);
- }
- for (int i=0; i<interfaces.size(); i++) {
- String INTERFACE = (String) interfaces.get(i);
- if (i>0) {
- stringBuffer.append(TEXT_10);
- }
- stringBuffer.append(INTERFACE);
- }
- stringBuffer.append(TEXT_11);
- List<EntityRow> fields = model.getEntityFields();
- for (EntityRow entity : fields) {
-
- stringBuffer.append(TEXT_12);
- stringBuffer.append(entity.getType());
- stringBuffer.append(TEXT_13);
- stringBuffer.append(entity.getName());
- stringBuffer.append(TEXT_14);
- }
- stringBuffer.append(TEXT_15);
- stringBuffer.append(model.getClassName());
- stringBuffer.append(TEXT_16);
-
- fields = model.getEntityFields();
- if (fields != null) for (int i=0; i<fields.size(); i++) {
- EntityRow field = (EntityRow) fields.get(i);
- String TYPE = field.getType();
- String NAME = field.getName();
- String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
-
- stringBuffer.append(TEXT_17);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_18);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_19);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_20);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_21);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_22);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_23);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_24);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_25);
- }
- stringBuffer.append(TEXT_26);
- stringBuffer.append(TEXT_27);
- return stringBuffer.toString();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java
deleted file mode 100644
index e212dbd707..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.*;
-import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JptUiIcons;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityDataModelProvider;
-import org.eclipse.jst.j2ee.internal.plugin.J2EEEditorUtility;
-import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
-import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
-
-public class EntityWizard extends DataModelWizard implements INewWizard {
-
-
- private static final String PAGE_ONE = "pageOne"; //$NON-NLS-1$
- private static final String PAGE_TWO = "pageTwo"; //$NON-NLS-1$
-
- /**
- * Constructs the Entity wizard
- * @param model the data model
- */
- public EntityWizard(IDataModel model) {
- super(model);
- setWindowTitle(EntityWizardMsg.ENTITY_WIZARD_TITLE);
- setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.ENTITY_WIZ_BANNER));
- }
-
- /**
- * Empty constructor
- */
- public EntityWizard(){
- this(null);
- }
-
- /* Adds the two pages of the entity wizard
- * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#doAddPages()
- */
- @Override
- protected void doAddPages() {
- EntityClassWizardPage page1 = new EntityClassWizardPage(
- getDataModel(),
- PAGE_ONE,
- EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_DESCRIPTION,
- EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_TITLE,
- J2EEProjectUtilities.EJB);
- addPage(page1);
- EntityFieldsWizardPage page2 = new EntityFieldsWizardPage(getDataModel(), PAGE_TWO);
- addPage(page2);
- }
-
- /* Return the default data model provider (EntityDataModelProvider in our case)
- * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#getDefaultProvider()
- */
- @Override
- protected IDataModelProvider getDefaultProvider() {
- return new EntityDataModelProvider();
- }
-
- /* Check whether the mandatory information is set and wizard could finish
- * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#canFinish()
- */
- @Override
- public boolean canFinish() {
- return getDataModel().isValid();
- }
-
- /*
- * Override the parent method in order to open the generated entity class in java editor
- * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#postPerformFinish()
- */
- @Override
- protected void postPerformFinish() throws InvocationTargetException {
- try {
- String className = getDataModel().getStringProperty(QUALIFIED_CLASS_NAME);
- IProject p = (IProject) getDataModel().getProperty(PROJECT);
- IJavaProject javaProject = J2EEEditorUtility.getJavaProject(p);
- IFile file = (IFile) javaProject.findType(className).getResource();
- openEditor(file);
- } catch (Exception cantOpen) {
- JptUiPlugin.log(cantOpen);
- }
- }
-
- /**
- * This method is intended for internal use only. It will open the file, sent as parameter
- * in its own java editor
- * @param file who should be opened
- */
- private void openEditor(final IFile file) {
- if (getDataModel().getBooleanProperty(OPEN_IN_EDITOR)) {
- if (file != null) {
- getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IDE.openEditor(page, file, true);
- }
- catch (PartInitException e) {
- JptUiPlugin.log(e);
- }
- }
- });
- }
- }
- }
-
- /* Implement the abstract method from IWorkbenchWizard
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
- */
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- getDataModel();
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java
deleted file mode 100644
index 6a03880499..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import com.ibm.icu.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import org.eclipse.osgi.util.NLS;
-
-public class EntityWizardMsg extends NLS {
-
- private static final String BUNDLE_NAME = "jpt_ui_entity_wizard";//$NON-NLS-1$
- private static ResourceBundle resourceBundle;
-
- public static String ENTITY_WIZARD_TITLE;
- public static String ADD_ENTITY_WIZARD_PAGE_TITLE;
- public static String ADD_ENTITY_WIZARD_PAGE_DESCRIPTION;
- public static String DEFAULT_PACKAGE_WARNING;
- public static String ENTITY_PROPERTIES_TITLE;
- public static String ENTITY_PROPERTIES_DESCRIPTION;
- public static String ENTITY;
- public static String MAPPED_AS_SUPERCLASS;
- public static String INHERITANCE_GROUP;
- public static String INHERITANCE_CHECK_BOX;
- public static String XML_STORAGE_GROUP;
- public static String XML_SUPPORT;
- public static String CHOOSE_XML;
- public static String MAPPING_XML_TITLE;
- public static String XML_NAME_TITLE;
- public static String INVALID_XML_NAME;
- public static String CHOOSE_MAPPING_XML_MESSAGE;
- public static String TYPE_DIALOG_TITLE;
- public static String TYPE_DIALOG_DESCRIPTION;
- public static String ENTITY_NAME;
- public static String TABLE_NAME;
- public static String TABLE_NAME_GROUP;
- public static String USE_DEFAULT;
- public static String ENTITY_FIELDS_DIALOG_TITLE;
- public static String ENTITY_FIELDS_GROUP;
- public static String KEY;
- public static String NAME_COLUMN;
- public static String TYPE_COLUMN;
- public static String NAME_TEXT_FIELD;
- public static String TYPE_TEXT_FIELD;
- public static String BROWSE_BUTTON_LABEL;
- public static String ADD_BUTTON_LABEL;
- public static String EDIT_BUTTON_LABEL;
- public static String EntityDataModelProvider_typeNotInProjectClasspath;
- public static String EntityDataModelProvider_invalidPKType;
- public static String EntityDataModelProvider_invalidArgument;
- public static String REMOVE_BUTTON_LABEL;
- public static String DUPLICATED_ENTITY_NAMES_MESSAGE;
- public static String ACCESS_TYPE;
- public static String FIELD_BASED;
- public static String PROPERTY_BASED;
- public static String NO_JPA_PROJECTS;
- public static String APPLY_CHANGES_TO_PERSISTENCE_XML;
- public static String ADD_MAPPED_SUPERCLASS_TO_XML;
- public static String ADD_ENTITY_TO_XML;
- private EntityWizardMsg() {
- // prevent instantiation of class
- }
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, EntityWizardMsg.class);
- }
-
- /**
- * Returns the resource bundle used by all classes in this Project
- */
- public static ResourceBundle getResourceBundle() {
- try {
- return ResourceBundle.getBundle(BUNDLE_NAME);//$NON-NLS-1$
- } catch (MissingResourceException e) {
- // does nothing - this method will return null and getString(String) will return
- // the key it was called with
- }
- return null;
- }
-
- /**
- * Returns the externalized string, mapped to this key
- * @param key
- * @return the text mapped to the key parameter
- */
- public static String getString(String key) {
- if (resourceBundle == null) {
- resourceBundle = getResourceBundle();
- }
-
- if (resourceBundle != null) {
- try {
- return resourceBundle.getString(key);
- } catch (MissingResourceException e) {
- //exception during string obtaining
- return "-" + key + "-";//$NON-NLS-2$//$NON-NLS-1$
- }
- }
- //return key, because the relevant string missing in the bundle
- return "+" + key + "+";//$NON-NLS-2$//$NON-NLS-1$
- }
-
- /**
- * Returns the formated string, mapped to this key
- * @param key
- * @param arguments
- * @return the formated text, mapped to this key, with substituted arguments
- */
- public static String getString(String key, Object[] arguments) {
- try {
- return MessageFormat.format(getString(key), arguments);
- } catch (IllegalArgumentException e) {
- return getString(key);
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java
deleted file mode 100644
index 1ea33feaff..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java
+++ /dev/null
@@ -1,255 +0,0 @@
-package org.eclipse.jpt.ui.internal.wizards.entity;
-
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
-import java.util.*;
-
-public class IdClassTemplate
-{
- protected static String nl;
- public static synchronized IdClassTemplate create(String lineSeparator)
- {
- nl = lineSeparator;
- IdClassTemplate result = new IdClassTemplate();
- nl = null;
- return result;
- }
-
- public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "package ";
- protected final String TEXT_2 = ";";
- protected final String TEXT_3 = NL;
- protected final String TEXT_4 = NL + "import ";
- protected final String TEXT_5 = ";";
- protected final String TEXT_6 = NL + NL + "/**" + NL + " * ID class for entity: ";
- protected final String TEXT_7 = NL + " *" + NL + " */ " + NL + "public class ";
- protected final String TEXT_8 = " ";
- protected final String TEXT_9 = " implements ";
- protected final String TEXT_10 = ", ";
- protected final String TEXT_11 = " { " + NL + " " + NL + "\t";
- protected final String TEXT_12 = " " + NL + "\tprivate ";
- protected final String TEXT_13 = " ";
- protected final String TEXT_14 = ";";
- protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic ";
- protected final String TEXT_16 = "() {}" + NL + "" + NL + "\t";
- protected final String TEXT_17 = NL + NL + "\tpublic ";
- protected final String TEXT_18 = " get";
- protected final String TEXT_19 = "() {" + NL + "\t\treturn this.";
- protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
- protected final String TEXT_21 = "(";
- protected final String TEXT_22 = " ";
- protected final String TEXT_23 = ") {" + NL + "\t\tthis.";
- protected final String TEXT_24 = " = ";
- protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t";
- protected final String TEXT_26 = NL + " " + NL + "\t/*" + NL + "\t * @see java.lang.Object#equals(Object)" + NL + "\t */\t" + NL + "\tpublic boolean equals(Object o) {" + NL + "\t\tif (o == this) {" + NL + "\t\t\treturn true;" + NL + "\t\t}" + NL + "\t\tif (!(o instanceof ";
- protected final String TEXT_27 = ")) {" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\t";
- protected final String TEXT_28 = " other = (";
- protected final String TEXT_29 = ") o;" + NL + "\t\treturn true";
- protected final String TEXT_30 = NL + "\t\t\t&& ";
- protected final String TEXT_31 = "() == other.";
- protected final String TEXT_32 = "()";
- protected final String TEXT_33 = NL + "\t\t\t&& (Double.doubleToLongBits(";
- protected final String TEXT_34 = "()) == Double.doubleToLongBits(other.";
- protected final String TEXT_35 = "()))";
- protected final String TEXT_36 = NL + "\t\t\t&& (Float.floatToIntBits(";
- protected final String TEXT_37 = "()) == Float.floatToIntBits(other.";
- protected final String TEXT_38 = "()))";
- protected final String TEXT_39 = NL + "\t\t\t&& (";
- protected final String TEXT_40 = "() == null ? other.";
- protected final String TEXT_41 = "() == null : ";
- protected final String TEXT_42 = "().equals(other.";
- protected final String TEXT_43 = "()))";
- protected final String TEXT_44 = ";" + NL + "\t}" + NL + "\t" + NL + "\t/*\t " + NL + "\t * @see java.lang.Object#hashCode()" + NL + "\t */\t" + NL + "\tpublic int hashCode() {" + NL + "\t\tfinal int prime = 31;" + NL + "\t\tint result = 1;";
- protected final String TEXT_45 = NL + "\t\tresult = prime * result + (";
- protected final String TEXT_46 = "() ? 1 : 0);";
- protected final String TEXT_47 = NL + "\t\tresult = prime * result + ";
- protected final String TEXT_48 = "();";
- protected final String TEXT_49 = NL + "\t\tresult = prime * result + ((int) ";
- protected final String TEXT_50 = "());";
- protected final String TEXT_51 = NL + "\t\tresult = prime * result + ((int) (";
- protected final String TEXT_52 = "() ^ (";
- protected final String TEXT_53 = "() >>> 32)));";
- protected final String TEXT_54 = NL + "\t\tresult = prime * result + ((int) (Double.doubleToLongBits(";
- protected final String TEXT_55 = "() ) ^ (Double.doubleToLongBits(";
- protected final String TEXT_56 = "()) >>> 32)));";
- protected final String TEXT_57 = NL + "\t\tresult = prime * result + Float.floatToIntBits(";
- protected final String TEXT_58 = "());";
- protected final String TEXT_59 = NL + "\t\tresult = prime * result + (";
- protected final String TEXT_60 = "() == null ? 0 : ";
- protected final String TEXT_61 = "().hashCode());";
- protected final String TEXT_62 = NL + "\t\treturn result;" + NL + "\t}" + NL + " " + NL + " " + NL + "}";
- protected final String TEXT_63 = NL;
-
- public String generate(Object argument)
- {
- final StringBuffer stringBuffer = new StringBuffer();
- CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
-if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
- stringBuffer.append(TEXT_1);
- stringBuffer.append(model.getJavaPackageName());
- stringBuffer.append(TEXT_2);
- }
- stringBuffer.append(TEXT_3);
- Collection<String> imports = model.getImports(true);
-for (String anImport : imports) {
- stringBuffer.append(TEXT_4);
- stringBuffer.append(anImport);
- stringBuffer.append(TEXT_5);
- }
- stringBuffer.append(TEXT_6);
- stringBuffer.append(model.getClassName());
- stringBuffer.append(TEXT_7);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_8);
- List<String> interfaces = model.getInterfaces();
- if (interfaces.size()>0) {
- stringBuffer.append(TEXT_9);
- }
- for (int i=0; i<interfaces.size(); i++) {
- String INTERFACE = (String) interfaces.get(i);
- if (i>0) {
- stringBuffer.append(TEXT_10);
- }
- stringBuffer.append(INTERFACE);
- }
- stringBuffer.append(TEXT_11);
- List<EntityRow> fields = model.getEntityFields();
- List<String> pkFields = model.getPKFields();
- for (int i=0; i<fields.size(); i++) {
- EntityRow entity = (EntityRow) fields.get(i);
- if (!pkFields.contains(entity.getName())) {
- continue;
- }
-
- stringBuffer.append(TEXT_12);
- stringBuffer.append(entity.getType());
- stringBuffer.append(TEXT_13);
- stringBuffer.append(entity.getName());
- stringBuffer.append(TEXT_14);
- }
- stringBuffer.append(TEXT_15);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_16);
-
- fields = model.getEntityFields();
- if (fields != null) for (int i=0; i<fields.size(); i++) {
- EntityRow field = (EntityRow) fields.get(i);
- String TYPE = field.getType();
- String NAME = field.getName();
- if (!pkFields.contains(NAME)) {
- continue;
- }
- String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
-
- stringBuffer.append(TEXT_17);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_18);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_19);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_20);
- stringBuffer.append(METHOD);
- stringBuffer.append(TEXT_21);
- stringBuffer.append(TYPE);
- stringBuffer.append(TEXT_22);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_23);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_24);
- stringBuffer.append(NAME);
- stringBuffer.append(TEXT_25);
- }
- stringBuffer.append(TEXT_26);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_27);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_28);
- stringBuffer.append(model.getIdClassName());
- stringBuffer.append(TEXT_29);
- if (fields != null) for (int i=0; i<fields.size(); i++) {
- EntityRow field = (EntityRow) fields.get(i);
- String NAME = field.getName();
- if (!pkFields.contains(NAME)) {
- continue;
- }
- String TYPE = field.getType();
- String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1);
- if (TYPE.equals("boolean") || TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short") || TYPE.equals("int") || TYPE.equals("long")) {
- stringBuffer.append(TEXT_30);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_31);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_32);
- } else if (TYPE.equals("double")) {
- stringBuffer.append(TEXT_33);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_34);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_35);
- } else if (TYPE.equals("float")) {
- stringBuffer.append(TEXT_36);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_37);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_38);
- } else {
- stringBuffer.append(TEXT_39);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_40);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_41);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_42);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_43);
- }
- }
- stringBuffer.append(TEXT_44);
- if (fields != null) for (int i=0; i<fields.size(); i++) {
- EntityRow field = (EntityRow) fields.get(i);
- String NAME = field.getName();
- if (!pkFields.contains(NAME)) {
- continue;
- }
- String TYPE = field.getType();
- String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1);
- if (TYPE.equals("boolean")) {
- stringBuffer.append(TEXT_45);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_46);
- } else if (TYPE.equals("int")) {
- stringBuffer.append(TEXT_47);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_48);
- } else if (TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short")) {
- stringBuffer.append(TEXT_49);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_50);
- } else if (TYPE.equals("long")) {
- stringBuffer.append(TEXT_51);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_52);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_53);
- } else if (TYPE.equals("double")) {
- stringBuffer.append(TEXT_54);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_55);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_56);
- } else if (TYPE.equals("float")) {
- stringBuffer.append(TEXT_57);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_58);
- } else {
- stringBuffer.append(TEXT_59);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_60);
- stringBuffer.append(GET_METHOD);
- stringBuffer.append(TEXT_61);
- }
- }
- stringBuffer.append(TEXT_62);
- stringBuffer.append(TEXT_63);
- return stringBuffer.toString();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java
deleted file mode 100644
index 5937f91978..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeSet;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.Signature;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
-import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-
-public class CreateEntityTemplateModel {
-
- protected IDataModel dataModel;
-
- private static final String DOT = "."; //$NON-NLS-1$
- private static final String BRACKET = "["; //$NON-NLS-1$
- private static final String PK_SUFFIX = "PK"; //$NON-NLS-1$
- private static final String QUALIFIED_SERIALIZABLE = "java.io.Serializable"; //$NON-NLS-1$
- private static final String PERSISTENCE_PACKAGE = "javax.persistence.*"; //$NON-NLS-1$
- private static final String ENTITY_ANNOTATION = "@Entity"; //$NON-NLS-1$
- private static final String MAPPED_AS_SUPERCLASS_TYPE = "@MappedSuperclass"; //$NON-NLS-1$
- private static final String INHERITANCE_TYPE = "@Inheritance"; //$NON-NLS-1$
-
- /**
- * Constructs entity model as expansion of the data model
- * @param dataModel
- */
- public CreateEntityTemplateModel(IDataModel dataModel) {
- this.dataModel = dataModel;
- }
-
- /**
- * Returns the necessary imports on depends of entity (primary keys) fields. It is used from
- * JET emmiter when it generates entity (IdClass)
- * @param isIdClass flag, which indicates the case. When it is false, the result is
- * the import list for the entity class, in other case the results is the set for the IdClass
- * generation
- * @return the imports collection with the imports for the generated java class
- */
- public Collection<String> getImports(boolean isIdClass) {
- Collection<String> collection = new TreeSet<String>();
-
- String className = getClassName();
- String superclassName = getQualifiedSuperclassName();
-
- if (superclassName != null && superclassName.length() > 0 &&
- !equalSimpleNames(className, superclassName)) {
- collection.add(superclassName);
- }
-
- List interfaces = getQualifiedInterfaces();
- if (interfaces != null) {
- Iterator iterator = interfaces.iterator();
- while (iterator.hasNext()) {
- String iface = (String) iterator.next();
- if (!equalSimpleNames(getClassName(), iface)) {
- collection.add(iface);
- }
- }
- }
- if (isIdClass) {
- collection.addAll(getIdClassImportList());
- } else {
- collection.add(PERSISTENCE_PACKAGE);
- collection.addAll(getFieldImportList());
-
- }
- return collection;
- }
-
- /**
- * @return class name of the entity
- */
- public String getClassName() {
- return getProperty(INewJavaClassDataModelProperties.CLASS_NAME).trim();
- }
-
- /**
- * @return package name when the entity will be generated
- */
- public String getJavaPackageName() {
- return getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE).trim();
- }
-
- /**
- * @return fully qualified java class name
- */
- public String getQualifiedJavaClassName() {
- if (!getJavaPackageName().equals(IEntityDataModelProperties.EMPTY_STRING)) {
- return getJavaPackageName() + DOT + getClassName();
- }
- return getClassName();
- }
-
- /**
- * @return the name
- */
- public String getSuperclassName() {
- String qualified = getQualifiedSuperclassName();
- if (equalSimpleNames(getClassName(), qualified)) {
- return qualified;
- } else {
- return Signature.getSimpleName(qualified);
- }
- }
-
- /**
- * @return fully qualified name of the entity's super class
- */
- public String getQualifiedSuperclassName() {
- return getProperty(INewJavaClassDataModelProperties.SUPERCLASS).trim();
- }
-
- /**
- * @return list with the interfaces implemented from entity class
- */
- public List<String> getInterfaces() {
- List qualifiedInterfaces = getQualifiedInterfaces();
- List<String> interfaces = new ArrayList<String>(qualifiedInterfaces.size());
-
- Iterator iter = qualifiedInterfaces.iterator();
- while (iter.hasNext()) {
- String qualified = (String) iter.next();
- if (equalSimpleNames(getClassName(), qualified)) {
- interfaces.add(qualified);
- } else {
- interfaces.add(Signature.getSimpleName(qualified));
- }
- }
-
- return interfaces;
- }
-
- /**
- * @return list with the interfaces (fully qualified named) implemented from entity class
- */
- public List getQualifiedInterfaces() {
- List interfaces = (List) this.dataModel.getProperty(INewJavaClassDataModelProperties.INTERFACES);
- if (interfaces == null){
- interfaces = new ArrayList();
- }
- interfaces.add(QUALIFIED_SERIALIZABLE);
- return interfaces;
- }
-
- /**
- * Returns the value of the specified string property
- * @param propertyName
- * @return string value of teh specified propert
- */
- protected String getProperty(String propertyName) {
- return dataModel.getStringProperty(propertyName);
- }
-
- /**
- * This methods is used for the comparison of fully qualified types
- * @param name1 first type name
- * @param name2 second type name
- * @return whether the simple names of the types are equal
- */
- protected boolean equalSimpleNames(String name1, String name2) {
- String simpleName1 = Signature.getSimpleName(name1);
- String simpleName2 = Signature.getSimpleName(name2);
- return simpleName1.equals(simpleName2);
- }
-
- /**
- * @return the type of the artifact - Entity or Mapped superclass
- */
- public String getArtifactType() {
- if(dataModel.getBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS)) {
- return MAPPED_AS_SUPERCLASS_TYPE;
- }
- return ENTITY_ANNOTATION;
- }
-
- /**
- * @return whether entity set inheritance strategy
- */
- public boolean isInheritanceSet() {
- return dataModel.getBooleanProperty(IEntityDataModelProperties.INHERITANCE);
- }
-
- /**
- * @return the name of the inheritance strategy, as it is defined in the specification
- */
- public String getInheritanceStrategyName() {
- return getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY);
- }
-
- /**
- * @return the constructed @Inheritance annotation with the relevant strategy
- * if it is chosen
- */
- public String getInheritanceStrategy() {
- String result = IEntityDataModelProperties.EMPTY_STRING;
- if (isInheritanceSet()) {
- result = INHERITANCE_TYPE;
- if (!getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY).equals(IEntityDataModelProperties.EMPTY_STRING)) { //$NON-NLS-1$
- result += "(strategy=InheritanceType." + getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY) + ")"; //$NON-NLS-1$ $NON-NLS-2$
-
- }
- }
- return result;
- }
-
- /**
- * @return whether the generated artifact is not entity
- */
- public boolean isNonEntitySuperclass() {
- return !dataModel.getBooleanProperty(IEntityDataModelProperties.ENTITY);
- }
-
- /**
- * @return true the created artifact will be annotated
- * @return false the entity mappings will be registered in XML
- */
- public boolean isArtifactsAnnotated() {
- return !dataModel.getBooleanProperty(IEntityDataModelProperties.XML_SUPPORT);
- }
-
- public boolean isMappingXMLDefault() {
- if (getMappingXMLName().equals(IEntityDataModelProperties.EMPTY_STRING)) {
- return true;
- }
- return getMappingXMLName().equals(JptCorePlugin.getDefaultOrmXmlDeploymentURI(getProject()));
- }
-
- public String getMappingXMLName() {
- return dataModel.getStringProperty(IEntityDataModelProperties.XML_NAME).trim();
- }
-
- public IFile getMappingXmlFile() {
- IFile ormFile = null;
- IProject project = getProject();
- IPackageFragmentRoot[] sourceFragments = J2EEProjectUtilities.getSourceContainers(project);
- for (IPackageFragmentRoot packageFragmentRoot : sourceFragments) {
- ormFile = project.getFile(packageFragmentRoot.getResource().getName() + File.separator + getMappingXMLName());
- if (ormFile.exists()) {
- break;
- }
- }
- return ormFile;
- }
-
- /**
- * @return the entity name (could be different from the class name)
- * See <code>isEntityNameSet()<code>
- */
- public String getEntityName() {
- return getProperty(IEntityDataModelProperties.ENTITY_NAME).trim();
- }
-
- /**
- * @return whether the entity name is different than class name
- */
- public boolean isEntityNameSet() {
- boolean result = false;
- if (!getClassName().equals(getEntityName())) {
- result = true;
- }
- return result;
- }
-
- /**
- * @return whether the table name is specified explicitly
- */
- public boolean isTableNameSet() {
- return !dataModel.getBooleanProperty(IEntityDataModelProperties.TABLE_NAME_DEFAULT);
- }
-
- /**
- * @return the table name (if it is specified)
- * See <code>isTableNameSet()<code>
- */
- public String getTableName() {
- return getProperty(IEntityDataModelProperties.TABLE_NAME).trim();
- }
-
- /**
- * @return list with the entity fields
- */
- public List<EntityRow> getEntityFields() {
- ArrayList<EntityRow> fields = (ArrayList<EntityRow>) dataModel.getProperty(IEntityDataModelProperties.ENTITY_FIELDS);
- if (fields == null){
- return new ArrayList<EntityRow>();
- } else
- return fields;
- }
-
- /**
- * @return list with the imports necessary for the entity (based on its fields)
- */
- public List<String> getFieldImportList() {
- List<String> imports = new ArrayList<String>();
- List<EntityRow> entities = getEntityFields();
- for (EntityRow entityRow : entities) {
- if (!imports.contains(entityRow.getFqnTypeName()) && !entityRow.getType().equals(entityRow.getFqnTypeName())) {
- String fqnTypeName = entityRow.getFqnTypeName();
- //remove the array brackets [] for the java.lang.Byte[] & java.lang.Character[]
- if (fqnTypeName.indexOf(BRACKET) != -1) {
- fqnTypeName = fqnTypeName.substring(0, fqnTypeName.indexOf("["));
- }
- imports.add(fqnTypeName);
- }
- }
- return imports;
- }
- /**
- * @return list with the imports necessary for the id class (based on its fields - primary keys of the entity)
- */
- public List<String> getIdClassImportList() {
- List<String> imports = new ArrayList<String>();
- List<EntityRow> entities = getEntityFields();
- List<String> pkFields = getPKFields();
- for (EntityRow entityRow : entities) {
- String name = entityRow.getName();
- if (pkFields.contains(name)) {
- if (!imports.contains(entityRow.getFqnTypeName()) && !entityRow.getType().equals(entityRow.getFqnTypeName())) {
- imports.add(entityRow.getFqnTypeName());
- }
- }
- }
- return imports;
- }
-
- /**
- * @return whether the access type is field based
- */
- public boolean isFieldAccess() {
- return dataModel.getBooleanProperty(IEntityDataModelProperties.FIELD_ACCESS_TYPE);
- }
-
- /**
- * @return the primary key is composite (more than one annotated as primary key field)
- */
- public boolean isCompositePK() {
- return getPKFields().size() > 1;
- }
-
- /**
- * @return list with primary key name(s)
- */
- public List<String> getPKFields() {
- return (ArrayList<String>)dataModel.getProperty(IEntityDataModelProperties.PK_FIELDS);
- }
-
- /**
- * @return constructed name of the id class (entity name + PK as suffix)
- */
- public String getIdClassName() {
- return getClassName() + PK_SUFFIX;
- }
-
- /**
- * @return IProject presentation of JPA project
- */
- public IProject getProject() {
- String projectName = dataModel.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
- return ProjectUtilities.getProject(projectName);
- }
-
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java
deleted file mode 100644
index 60d9ec9d48..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008, 2009 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
-
-import com.ibm.icu.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jpt.core.JpaFile;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation;
-import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
-
-public class EntityDataModelProvider extends NewJavaClassDataModelProvider implements IEntityDataModelProperties{
-
- @Override
- public IDataModelOperation getDefaultOperation() {
- return new NewEntityClassOperation(getDataModel());
- }
-
- /**
- * Extends: <code>IDataModelProvider#getPropertyNames()</code>
- * and add own data model's properties specific for the entity model
- *
- * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames()
- */
- @Override
- public Set getPropertyNames() {
- Set propertyNames = super.getPropertyNames();
- propertyNames.add(INHERITANCE);
- propertyNames.add(ENTITY);
- propertyNames.add(MAPPED_AS_SUPERCLASS);
- propertyNames.add(INHERITANCE_STRATEGY);
- propertyNames.add(XML_SUPPORT);
- propertyNames.add(XML_NAME);
- propertyNames.add(ENTITY_NAME);
- propertyNames.add(TABLE_NAME_DEFAULT);
- propertyNames.add(TABLE_NAME);
- propertyNames.add(ENTITY_FIELDS);
- propertyNames.add(PK_FIELDS);
- propertyNames.add(FIELD_ACCESS_TYPE);
- propertyNames.add(PROPERTY_ACCESS_TYPE);
- return propertyNames;
- }
-
- /**
- * Returns the default value of the parameter (which should present a valid data model property).
- * This method does not accept a null parameter. It may return null.
- *
- * @see NewJavaClassDataModelProvider#getDefaultProperty(String)
- * @see IDataModelProvider#getDefaultProperty(String)
- *
- * @param propertyName
- * @return Object default value of property
- */
- @Override
- public Object getDefaultProperty(String propertyName) {
- if (propertyName.equals(INHERITANCE)) {
- return Boolean.FALSE;
- } else if (propertyName.equals(ENTITY)) {
- return Boolean.TRUE;
- } else if (propertyName.equals(MAPPED_AS_SUPERCLASS)) {
- return Boolean.FALSE;
- } else if (propertyName.equals(XML_SUPPORT)) {
- return Boolean.FALSE;
- } else if (propertyName.equals(XML_NAME)) {
- return EMPTY_STRING;
- } else if (propertyName.equals(ENTITY_NAME)) {
- return getStringProperty(CLASS_NAME);
- } else if (propertyName.equals(TABLE_NAME_DEFAULT)) {
- return Boolean.TRUE;
- } else if (propertyName.equals(TABLE_NAME)) {
- return getStringProperty(CLASS_NAME);
- } else if (propertyName.equals(INHERITANCE_STRATEGY)) {
- return EMPTY_STRING;
- } else if (propertyName.equals(SUPERCLASS)) {
- return EMPTY_STRING;
- } else if (propertyName.equals(ENTITY_FIELDS)) {
- return new ArrayList<EntityRow>();
- } else if (propertyName.equals(PK_FIELDS)) {
- return new ArrayList<String>();
- } else if (propertyName.equals(FIELD_ACCESS_TYPE)) {
- return Boolean.TRUE;
- } else if (propertyName.equals(PROPERTY_ACCESS_TYPE)) {
- return Boolean.FALSE;
- }
- // Otherwise check super for default value for property
- return super.getDefaultProperty(propertyName);
- }
-
- @Override
- public boolean propertySet(String propertyName, Object propertyValue) {
- boolean ok = super.propertySet(propertyName, propertyValue);
- if (propertyName.equals(PROJECT_NAME) || propertyName.equals(XML_SUPPORT)) {
- this.model.notifyPropertyChange(XML_NAME, IDataModel.VALID_VALUES_CHG);
- }
- return ok;
- }
-
- /* Adds additional check to the model validation
- * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider#validate(java.lang.String)
- */
- @Override
- public IStatus validate(String propertyName) {
- IStatus result = super.validate(propertyName);
- if (propertyName.equals(JAVA_PACKAGE)) {
- return validateJavaPackage(getStringProperty(propertyName));
- }
- if (propertyName.equals(SUPERCLASS) && EMPTY_STRING.equals(getStringProperty(propertyName))) {
- return WTPCommonPlugin.OK_STATUS;
- }
- if (propertyName.equals(XML_NAME)) {
- return validateXmlName(getStringProperty(propertyName));
- }
- if (propertyName.equals(ENTITY_FIELDS)) {
- return validateFieldsList((ArrayList<EntityRow>) getProperty(propertyName));
- }
- return result;
- }
-
- /**
- * This method is intended for internal use only. It will be used to validate the correctness of entity package
- * in accordance with Java convention requirements. This method will accept a null parameter.
- *
- * @see NewFilterClassDataModelProvider#validate(String)
- *
- * @param packName
- * @return IStatus is the package name satisfies Java convention requirements
- */
-
- private IStatus validateJavaPackage(String packName) {
- if (packName == null || packName.equals(EMPTY_STRING)) {
- return WTPCommonPlugin.createWarningStatus(EntityWizardMsg.DEFAULT_PACKAGE_WARNING);
- }
- // Use standard java conventions to validate the package name
- IStatus javaStatus = JavaConventions.validatePackageName(packName, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
- if (javaStatus.getSeverity() == IStatus.ERROR) {
- String msg = J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage();
- return WTPCommonPlugin.createErrorStatus(msg);
- } else if (javaStatus.getSeverity() == IStatus.WARNING) {
- String msg = J2EECommonMessages.ERR_JAVA_PACKAGE_NAME_WARNING + javaStatus.getMessage();
- return WTPCommonPlugin.createWarningStatus(msg);
- }
- // java package name is valid
- return WTPCommonPlugin.OK_STATUS;
- }
-
- /**
- * This method is intended for internal use only. It will be used to validate
- * the correctness of xml file location.
- * This method will accept a null parameter.
- *
- * @see NewFilterClassDataModelProvider#validate(String)
- *
- * @param xmlName
- * @return IStatus is the package name satisfies Java convention requirements
- */
- private IStatus validateXmlName(String xmlName) {
- if (getBooleanProperty(XML_SUPPORT)) {
- String projectName = this.model.getStringProperty(PROJECT_NAME);
- IProject project = ProjectUtilities.getProject(projectName);
- if (project != null) {
- //TODO need to check content type as well since user can type in a file name, should have a different error message for invalid content type
- JpaFile jpaFile = JptCorePlugin.getJpaFile(project, xmlName);
- if (jpaFile == null) {
- return new Status(
- IStatus.ERROR, JptUiPlugin.PLUGIN_ID,
- EntityWizardMsg.INVALID_XML_NAME);
- }
- }
- }
- return Status.OK_STATUS;
- }
-
-
- /**
- * This method is intended for internal use only. It will be used to validate the entity fields
- * list to ensure there are not any duplicates. This method will accept a null parameter.
- *
- * @see NewFilterClassDataModelProvider#validate(String)
- *
- * @param entities
- * @return IStatus is the fields names are unique
- */
- private IStatus validateFieldsList(ArrayList<EntityRow> entities) {
- if (entities != null && !entities.isEmpty()) {
- // Ensure there are not duplicate entries in the list
- boolean dup = hasDuplicatesInEntityFields(entities);
- if (dup) {
- String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE;
- return WTPCommonPlugin.createErrorStatus(msg);
- }
- // Ensure that the entries in the list are valid
- String errorMsg = checkInputElementsTypeValidation(entities);
- if (errorMsg != null) {
- return WTPCommonPlugin.createErrorStatus(errorMsg);
- }
- String warningMsg = checkInputElementsTypeExistence(entities);
- if (warningMsg != null) {
- return WTPCommonPlugin.createWarningStatus(warningMsg);
- }
- }
- return WTPCommonPlugin.OK_STATUS;
- }
-
- private String checkInputElementsTypeValidation(List<EntityRow> inputElements) {
- IStatus validateFieldTypeStatus = Status.OK_STATUS;
- for (EntityRow entityRow: inputElements) {
- if (entityRow.isKey() && !entityRow.couldBeKey()) {
- String message = MessageFormat.format(
- EntityWizardMsg.EntityDataModelProvider_invalidPKType, new Object[]{entityRow.getFqnTypeName()});
- validateFieldTypeStatus = new Status(IStatus.ERROR,
- JptUiPlugin.PLUGIN_ID, message);
- break;
- }
- String sig = null;
- try {
- sig = Signature.createTypeSignature(entityRow.getFqnTypeName(), true);
- } catch (IllegalArgumentException e) {
- String message = MessageFormat.format(EntityWizardMsg.EntityDataModelProvider_invalidArgument, new Object[]{e.getLocalizedMessage()});
- validateFieldTypeStatus = new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, message);
- break;
- }
- if (sig == null){
- validateFieldTypeStatus = JavaConventions.validateJavaTypeName(entityRow.getType(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
- break;
- }
- int sigType = Signature.getTypeSignatureKind(sig);
- if (sigType == Signature.BASE_TYPE_SIGNATURE) {
- continue;
- }
- else if (sigType == Signature.ARRAY_TYPE_SIGNATURE) {
- String elementSignature = Signature.getElementType(sig);
- if (Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE) {
- continue;
- }
- }
- }
- if (!validateFieldTypeStatus.isOK()) {
- return validateFieldTypeStatus.getMessage();
- }
- return null;
- }
-
- private String checkInputElementsTypeExistence(List<EntityRow> inputElements) {
- IStatus validateFieldTypeStatus=Status.OK_STATUS;
- for (EntityRow entityRow: inputElements) {
- String sig = Signature.createTypeSignature(entityRow.getFqnTypeName() ,true);
- if (sig == null) {
- String message = MessageFormat.format(
- EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
- validateFieldTypeStatus = new Status(IStatus.ERROR,
- JptUiPlugin.PLUGIN_ID, message);
- break;
- }
- int sigType = Signature.getTypeSignatureKind(sig);
- if (sigType == Signature.BASE_TYPE_SIGNATURE){
- continue;
- }
- else if (sigType == Signature.ARRAY_TYPE_SIGNATURE) {
- String elementSignature = Signature.getElementType(sig);
- if(Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE){
- continue;
- }
- String qualifiedName = Signature.toString(elementSignature);
- IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT);
- IJavaProject javaProject = JavaCore.create(project);
- IType type = null;
- try {
- type = javaProject.findType(qualifiedName);
- } catch (JavaModelException e) {
- validateFieldTypeStatus = e.getStatus();
- break;
- }
- if (type == null) {
- String message = MessageFormat.format(
- EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
- validateFieldTypeStatus = new Status(IStatus.ERROR,
- JptUiPlugin.PLUGIN_ID, message);
- break;
- }
- }
- else {
- IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT);
- IJavaProject javaProject = JavaCore.create(project);
- IType type = null;
- try {
- type = javaProject.findType(entityRow.getFqnTypeName());
- } catch (JavaModelException e) {
- validateFieldTypeStatus = e.getStatus();
- break;
- }
- if (type == null) {
- String message = MessageFormat.format(
- EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
- validateFieldTypeStatus = new Status(IStatus.ERROR,
- JptUiPlugin.PLUGIN_ID, message);
- break;
- }
- }
- }
- if(!validateFieldTypeStatus.isOK()) {
- return validateFieldTypeStatus.getMessage();
- }
- return null;
- }
-
-
-
- /**
- * This method is intended for internal use only. It provides a simple algorithm for detecting
- * if there are duplicate entries in a list. It will accept a null parameter. It will return
- * boolean.
- *
- * @param input
- * @return boolean are there duplications in the list
- */
- private boolean hasDuplicatesInEntityFields(ArrayList<EntityRow> input) {
- if (input == null) {
- return false;
- }
- int n = input.size();
- // nested for loops to check each element to see if other elements are the same
- for (int i = 0; i < n; i++) {
- EntityRow entity = input.get(i);
- for (int j = i + 1; j < n; j++) {
- EntityRow intEntity = input.get(j);
- if (intEntity.getName().equals(entity.getName())) {
- return true;
- }
- }
- }
- return false;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java
deleted file mode 100644
index 4475ea6503..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class EntityRow {
-
- private static final String DOT = ".";
- private static final char BRACKET_SQUARE = '[';
- private static final char BRACKET_ANGULAR = '<';
- private static final String PACKAGE_JAVA_LANG = "java.lang.";
- private boolean key = false;
- private String name = "";
- private String type = "";
- private String fqnTypeName = "";
-
- private final static String[] PK_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float",
- "java.lang.String", "java.sql.Date", "java.util.Date", "java.lang.Integer", "java.lang.Long", "java.lang.Short",
- "java.lang.Character", "java.lang.Boolean", "java.lang.Byte", "java.lang.Double", "java.lang.Float"};
-
- private final static String[] PK_TYPES_SHORT = { "String", "Integer", "Long", "Short", "Character", "Boolean",
- "Byte", "Double", "Float" };
-
- private final static List<String> VALID_PK_TYPES = Arrays.asList(PK_TYPES);
- private final static List<String> VALID_PK_TYPES_SHORT = Arrays.asList(PK_TYPES_SHORT);
-
- /**
- * @return whether the presented entity field is primary key or part of composite primary key
- */
- public boolean isKey() {
- return key;
- }
-
- /**
- * Sets the presented entity field to be primary key (or part of composite primari key)
- *
- * @param key
- */
- public void setKey(boolean key) {
- this.key = key;
- }
-
- /**
- * Check whether the type of the entity is allowed to be primary key.
- * The limitation in the current implementation is that Embedded PK are not checked
- * @return whether the type of field could be used as primary key
- */
- public boolean couldBeKey() {
- boolean result = false;
- result = VALID_PK_TYPES.contains(getFqnTypeName());
- return result;
- }
-
- /**
- * @return the name of the entity field
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name of the presented entity field
- * @param name
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the type (as a simple name) of the entity field
- */
- public String getType() {
- return type;
- }
-
- /**
- * Sets the type (as a simple name) of the entity field
- *
- * @param type
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @return the type (as fully qualified name) of the entity field
- */
- public String getFqnTypeName() {
- return fqnTypeName;
- }
-
- private String removeSpaces(String str) {
- str = str.trim();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < str.length(); i++) {
- char c = str.charAt(i);
- if (!Character.isWhitespace(c))
- sb.append(c);
- }
- return sb.toString();
- }
-
- private String getBasicFQN(String fqn) {
- String res;
- int bsIndex = fqn.indexOf(BRACKET_SQUARE);
- int baIndex = fqn.indexOf(BRACKET_ANGULAR);
- if (bsIndex == -1) {
- if (baIndex == -1) res = fqn;
- else res = fqn.substring(0, baIndex);
- } else {
- if (baIndex == -1) res = fqn.substring(0, bsIndex);
- else res = fqn.substring(0, Math.max(bsIndex, baIndex));
- }
- return res;
- }
-
- /**
- * Sets the fully qualified type name of the entity field
- *
- * @param fqnTypeName
- */
- public void setFqnTypeName(String fqnTypeName) {
- fqnTypeName = removeSpaces(fqnTypeName);
- String fqnBasicTypeName = getBasicFQN(fqnTypeName);
- if (fqnBasicTypeName.indexOf(DOT) == -1) {
- if (VALID_PK_TYPES_SHORT.contains(fqnBasicTypeName)) {
- this.fqnTypeName = PACKAGE_JAVA_LANG + fqnTypeName;
- setType(fqnTypeName);
- } else {
- this.fqnTypeName = fqnTypeName;
- setType(fqnTypeName);
- }
- } else {
- this.fqnTypeName = fqnTypeName;
- setType(getSimpleName(fqnTypeName));
- }
- }
-
- /**
- * @return whether the type of the entity field is boolean. The information could be used
- * when the name of getter should be constructed
- */
- public boolean isBoolean() {
- return "boolean".equals(getType());
- }
-
- /**
- * For internal purpose only
- * Convert fully qualified name to the simple one
- * @param fullyName
- * @return the simple name form the fully qualified name parameter(last segment)
- */
- private String getSimpleName(String fullyName) {
- return fullyName.substring(fullyName.lastIndexOf(DOT) + 1);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((fqnTypeName == null) ? 0 : fqnTypeName.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- /*
- * Implement equals, depending from name of the entity field and its type.
- * The type is presented from the fully qualified name
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final EntityRow other = (EntityRow) obj;
- if (fqnTypeName == null) {
- if (other.fqnTypeName != null)
- return false;
- } else if (!fqnTypeName.equals(other.fqnTypeName))
- return false;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- return true;
- }
-
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java
deleted file mode 100644
index 9a03daa303..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
-
-import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-
-public interface IEntityDataModelProperties extends INewJavaClassDataModelProperties, IAnnotationsDataModel {
-
- public static final String ENTITY = "IEntityDataModelProperties.ENTITY"; //$NON-NLS-1$
- public static final String MAPPED_AS_SUPERCLASS = "IEntityDataModelProperties.MAPPED_AS_SUPERCLASS"; //$NON-NLS-1$
- public static final String INHERITANCE = "IEntityDataModelProperties.INHERITANCE"; //$NON-NLS-1$
- public static final String INHERITANCE_STRATEGY = "IEntityDataModelProperties.INHERITANCE_STRATEGY"; //$NON-NLS-1$
- public static final String XML_SUPPORT = "IEntityDataModelProperties.XML_SUPPORT"; //$NON-NLS-1$XML_SUPPORT
- public static final String XML_NAME = "IEntityDataModelProperties.XML_NAME"; //$NON-NLS-1$XML_SUPPORT
- public static final String ENTITY_NAME = "IEntityDataModelProperties.ENTITY_NAME"; //$NON-NLS-1$
- public static final String TABLE_NAME_DEFAULT = "IEntityDataModelProperties.TABLE_NAME_DEFAULT"; //$NON-NLS-1$
- public static final String TABLE_NAME = "IEntityDataModelProperties.TABLE_NAME"; //$NON-NLS-1$
- public static final String ENTITY_FIELDS = "IEntityDataModelProperties.ENTITY_FIELDS"; //$NON-NLS-1$
- public static final String PK_FIELDS = "IEntityDataModelProperties.PK_FIELDS"; //$NON-NLS-1$
- public static final String FIELD_ACCESS_TYPE = "IEntityDataModelProperties.FIELD_ACCESS_TYPE"; //$NON-NLS-1$
- public static final String PROPERTY_ACCESS_TYPE = "IEntityDataModelProperties.PROPERTY_ACCESS_TYPE"; //$NON-NLS-1$
- public static final String EMPTY_STRING = ""; //$NON-NLS-1$
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
deleted file mode 100644
index 96005c08f9..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
+++ /dev/null
@@ -1,534 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2008, 2009 by SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
- ***********************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.entity.data.operation;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaModelMarker;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.MappingKeys;
-import org.eclipse.jpt.core.context.AccessType;
-import org.eclipse.jpt.core.context.Entity;
-import org.eclipse.jpt.core.context.InheritanceType;
-import org.eclipse.jpt.core.context.MappedSuperclass;
-import org.eclipse.jpt.core.context.orm.EntityMappings;
-import org.eclipse.jpt.core.context.orm.OrmPersistentType;
-import org.eclipse.jpt.core.resource.orm.OrmFactory;
-import org.eclipse.jpt.core.resource.persistence.PersistenceFactory;
-import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef;
-import org.eclipse.jpt.core.resource.persistence.XmlPersistence;
-import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
-import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.wizards.entity.AnnotatedEntityTemplate;
-import org.eclipse.jpt.ui.internal.wizards.entity.EntityTemplate;
-import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
-import org.eclipse.jpt.ui.internal.wizards.entity.IdClassTemplate;
-import org.eclipse.jpt.ui.internal.wizards.entity.data.model.CreateEntityTemplateModel;
-import org.eclipse.jst.common.internal.annotations.controller.AnnotationsController;
-import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager;
-import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
-import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
-import org.eclipse.jst.j2ee.internal.project.WTPJETEmitter;
-import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
-import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.internal.enablement.nonui.WFTWrappedException;
-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
-
-/**
- * The NewEntityClassOperation is IDataModelOperation following the
- * IDataModel wizard and operation framework.
- *
- * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation
- * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider
- *
- * This operation is used to generate java classes for the new JPA entity. It uses
- * EntityDataModelProvider to store the appropriate properties required to generate the new entity.
- * @see org.eclipse.jpt.ui.internal.wizards.entity.data.modelEntityDataModelProvider
- *
- * A WTPJetEmitter entity template is used to create the class with the entity template.
- * @see org.eclipse.jst.j2ee.internal.project.WTPJETEmitter
- * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.CreateEntityTemplateModel
- *
- * The use of this class is EXPERIMENTAL and is subject to substantial changes.
- */
-public class NewEntityClassOperation extends AbstractDataModelOperation {
-
- private static final String DOT_JAVA = ".java"; //$NON-NLS-1$
- private static final String SEPARATOR = "/";//$NON-NLS-1$
- private static final String VERSION_STRING = "1.0";//$NON-NLS-1$
- private static final String FIELD = "FIELD";//$NON-NLS-1$
- private static final String PROPERTY = "PROPERTY";//$NON-NLS-1$
- protected static final String WTP_CUSTOMIZATION_PLUGIN = "WTP_CUSTOMIZATION_PLUGIN"; //$NON-NLS-1$
- protected static final String ANNOTATED_ENTITY_TEMPLATE_FILE = "/templates/annotated_entity.javajet"; //$NON-NLS-1$
- protected static final String ENTITY_TEMPLATE_FILE = "/templates/entity.javajet"; //$NON-NLS-1$
- protected static final String IDCLASS_TEMPLATE_FILE = "/templates/idClass.javajet"; //$NON-NLS-1$
- protected static final String BUILDER_ID = "builderId"; //$NON-NLS-1$
- private static final String EMPTY_STRING = "";//$NON-NLS-1$
- private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$
-
- /**
- * Method name of template implementation classes.
- */
- protected static final String GENERATE_METHOD = "generate"; //$NON-NLS-1$
-
- /**
- * This is the constructor which should be used when creating a NewEntityClassOperation.
- * An instance of the CreateEntityTemplateModel should be passed in. This does not accept
- * null parameter. It will not return null.
- *
- * @see ArtifactEditProviderOperation#ArtifactEditProviderOperation(IDataModel)
- * @see CreateEntityTemplateModel
- *
- * @param dataModel
- * @return NewFilterClassOperation
- */
- public NewEntityClassOperation(IDataModel dataModel) {
- super(dataModel);
- }
-
- /**
- * The implementation of the execute method drives the running of the operation.
- * This implementation will create the java source folder, create the java package, and then
- * the entity (or mapped as superclass) and ID class files will be created using templates.
- *
- * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
- * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor,
- * IPackageFragment)
- *
- * @param monitor
- * @throws CoreException
- * @throws InterruptedException
- * @throws InvocationTargetException
- */
- public IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- // Create source folder if it does not exist
- createJavaSourceFolder();
- // Create java package if it does not exist
- IPackageFragment pack = createJavaPackage();
- // Generate filter class using templates
- try {
- generateUsingTemplates(monitor, pack);
- } catch (Exception e) {
- return WTPCommonPlugin.createErrorStatus(e.toString());
- }
- return OK_STATUS;
- }
-
- /**
- * This method will return the java package as specified by the new java
- * class data model. If the package does not exist, it will create the
- * package. This method should not return null.
- *
- * @see INewJavaClassDataModelProperties#JAVA_PACKAGE
- * @see IPackageFragmentRoot#createPackageFragment(java.lang.String,
- * boolean, org.eclipse.core.runtime.IProgressMonitor)
- *
- * @return IPackageFragment the java package
- */
- protected final IPackageFragment createJavaPackage() {
- // Retrieve the package name from the java class data model
- String packageName = model.getStringProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE);
- IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model
- .getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
- IPackageFragment pack = packRoot.getPackageFragment(packageName);
- // Handle default package
- if (pack == null) {
- pack = packRoot.getPackageFragment(""); //$NON-NLS-1$
- }
-
- // Create the package fragment if it does not exist
- if (!pack.exists()) {
- String packName = pack.getElementName();
- try {
- pack = packRoot.createPackageFragment(packName, true, null);
- } catch (JavaModelException e) {
- Logger.getLogger().log(e);
- }
- }
- // Return the package
- return pack;
- }
-
- /**
- * This implementation uses the creation of a CreateEntityTemplateModel and the WTPJETEmitter
- * to create the java class with the annotated tags. This method accepts null for monitor, it does not accept null
- * for fragment. If annotations are not being used the tags will be omitted from the class.
- *
- * @see CreateEntityTemplateModel
- * @see NewEntityClassOperation#generateTemplateSource(CreateEntityTemplateModel,
- * IProgressMonitor)
- *
- * @param monitor
- * @param fragment
- * @throws CoreException
- * @throws WFTWrappedException
- */
- protected void generateUsingTemplates(IProgressMonitor monitor, IPackageFragment fragment) throws WFTWrappedException, CoreException {
- // Create the entity template model
- CreateEntityTemplateModel tempModel = createTemplateModel();
- IProject project = getTargetProject();
- String entityClassSource = null;
- String idClassSource = null;
- // Generate the java source based on the entity template models
- try {
- if (tempModel.isArtifactsAnnotated()) {
- AnnotatedEntityTemplate tempImpl = AnnotatedEntityTemplate.create(null);
- entityClassSource = generateTemplateSource(tempModel, ANNOTATED_ENTITY_TEMPLATE_FILE, tempImpl, monitor);
- } else {
- EntityTemplate tempImpl = EntityTemplate.create(null);
- entityClassSource = generateTemplateSource(tempModel, ENTITY_TEMPLATE_FILE, tempImpl, monitor);
- }
- if (tempModel.isCompositePK()) {
- IdClassTemplate tempImpl = IdClassTemplate.create(null);
- idClassSource = generateTemplateSource(tempModel, IDCLASS_TEMPLATE_FILE, tempImpl, monitor);
- }
- } catch (Exception e) {
- throw new WFTWrappedException(e);
- }
- if (fragment != null) {
- // Create the java file
- String javaFileName = tempModel.getClassName() + DOT_JAVA;
- ICompilationUnit cu = fragment.getCompilationUnit(javaFileName);
- // Add the compilation unit to the java file
- if (cu == null || !cu.exists()) {
- cu = fragment.createCompilationUnit(javaFileName, entityClassSource, true, monitor);
- }
- IFile aFile = (IFile) cu.getResource();
- // Let the annotations controller process the annotated resource
- if (tempModel.isArtifactsAnnotated()) {
- AnnotationsController controller = AnnotationsControllerManager.INSTANCE.getAnnotationsController(project);
- if (controller != null) {
- controller.process(aFile);
- }
- }
- //Create IdClass if the primary key is complex
- if (idClassSource != null) {
- String entityPKName = tempModel.getIdClassName() + DOT_JAVA;
- ICompilationUnit cu1 = fragment.getCompilationUnit(entityPKName);
- // Add the compilation unit to the java file
- if (cu1 == null || !cu1.exists()) {
- cu1 = fragment.createCompilationUnit(entityPKName, idClassSource, true, monitor);
- }
- }
- }
-
- if (!tempModel.isArtifactsAnnotated()) {
- if (tempModel.isNonEntitySuperclass()) {
- addMappedSuperclassToXML(tempModel, project).schedule();
- } else {
- addEntityToXML(tempModel, project).schedule();
- }
- }
- if (tempModel.isArtifactsAnnotated() && !JptCorePlugin.discoverAnnotatedClasses(project)) {
- registerClassInPersistenceXml(tempModel, project).schedule();
- }
- }
-
- /**
- * This method is intended for internal use only. This method will create an
- * instance of the CreateEntityTemplateModel model to be used in conjunction
- * with the WTPJETEmitter. This method will not return null.
- *
- * @see CreateEntityTemplateModel
- * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor,
- * IPackageFragment)
- *
- * @return CreateFilterTemplateModel
- */
- private CreateEntityTemplateModel createTemplateModel() {
- CreateEntityTemplateModel templateModel = new CreateEntityTemplateModel(model);
- return templateModel;
- }
-
- /**
- * This method is intended for internal use only. This will use the
- * WTPJETEmitter to create an annotated java file based on the passed template model.
- * This method does not accept null parameters. It will not return null.
- * If annotations are not used, it will use the non annotated template to omit the annotated tags.
- *
- * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor,
- * IPackageFragment)
- * @see JETEmitter#generate(org.eclipse.core.runtime.IProgressMonitor,
- * java.lang.Object[])
- * @see CreateEntityTemplateModel
- *
- * @param templateModel
- * @param monitor
- * @param template_file
- * @return String the source for the java file
- * @throws JETException
- * @throws NoSuchMethodException
- * @throws SecurityException
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- private String generateTemplateSource(CreateEntityTemplateModel templateModel, String templateFile, Object templateImpl, IProgressMonitor monitor)
- throws JETException, SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Preferences preferences = J2EEPlugin.getDefault().getPluginPreferences();
- boolean dynamicTranslation = preferences.getBoolean(J2EEPlugin.DYNAMIC_TRANSLATION_OF_JET_TEMPLATES_PREF_KEY);
- if (dynamicTranslation) {
- URL templateURL = FileLocator.find(JptUiPlugin.instance().getBundle(), new Path(templateFile), null);
- cleanUpOldEmitterProject();
- WTPJETEmitter emitter = new WTPJETEmitter(templateURL.toString(), this.getClass().getClassLoader());
- emitter.setIntelligentLinkingEnabled(true);
- emitter.addVariable(WTP_CUSTOMIZATION_PLUGIN, JptUiPlugin.PLUGIN_ID);
- return emitter.generate(monitor, new Object[] { templateModel });
- } else {
- Method method = templateImpl.getClass().getMethod(GENERATE_METHOD, new Class[] { Object.class });
- return (String) method.invoke(templateImpl, templateModel);
- }
- }
-
- /**
- * This method is intended for internal use only. It will clean up the old emmiter project
- * in order to prevent generation issues
- */
- private void cleanUpOldEmitterProject() {
- IProject project = ProjectUtilities.getProject(WTPJETEmitter.PROJECT_NAME);
- if (project == null || !project.exists())
- return;
- try {
- IMarker[] markers = project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
- for (int i = 0, l = markers.length; i < l; i++) {
- if (((Integer) markers[i].getAttribute(IMarker.SEVERITY)).intValue() == IMarker.SEVERITY_ERROR) {
- project.delete(true, new NullProgressMonitor());
- break;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * This method will return the java source folder as specified in the java
- * class data model. It will create the java source folder if it does not
- * exist. This method may return null.
- *
- * @see INewJavaClassDataModelProperties#SOURCE_FOLDER
- * @see IFolder#create(boolean, boolean,
- * org.eclipse.core.runtime.IProgressMonitor)
- *
- * @return IFolder the java source folder
- */
- protected final IFolder createJavaSourceFolder() {
- // Get the source folder name from the data model
- String folderFullPath = model.getStringProperty(INewJavaClassDataModelProperties.SOURCE_FOLDER);
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IFolder folder = root.getFolder(new Path(folderFullPath));
- // If folder does not exist, create the folder with the specified path
- if (!folder.exists()) {
- try {
- folder.create(true, true, null);
- } catch (CoreException e) {
- Logger.getLogger().log(e);
- }
- }
- // Return the source folder
- return folder;
- }
-
- @Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- return doExecute(monitor, info);
- }
-
- public IProject getTargetProject() {
- String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
- return ProjectUtilities.getProject(projectName);
- }
-
- /**
- * Adds entity to ORM XML in separate job
- * @param model entity data model
- * @param project JPA project in which the entity will be created
- * @return
- */
- private Job addEntityToXML(final CreateEntityTemplateModel model, final IProject project) {
- Job job = new Job(EntityWizardMsg.ADD_ENTITY_TO_XML) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- final JpaXmlResource xmlResource = getOrmXmlResource(model, project);
- EntityMappings entityMappings = (EntityMappings) JptCorePlugin.getJpaProject(project).getJpaFile(xmlResource.getFile()).rootStructureNodes().next();
- OrmPersistentType persistentType = entityMappings.addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, model.getQualifiedJavaClassName());
- Entity entity = (Entity) persistentType.getMapping();
- if (model.isInheritanceSet()) {
- entity.setSpecifiedInheritanceStrategy(getModelInheritanceType(model));
- }
-
- if (model.isEntityNameSet()) {
- entity.setSpecifiedName(model.getEntityName());
- }
- if (model.isTableNameSet()) {
- entity.getTable().setSpecifiedName(model.getTableName());
- }
- if (model.isCompositePK()) {
- entity.setIdClass(model.getIdClassName());
- }
- for (String fieldName : model.getPKFields()) {
- persistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, fieldName);
- }
-
- persistentType.setSpecifiedAccess(getModelAccessType(model));
-
- try {
- xmlResource.saveIfNecessary();
- }
- catch (Exception e) {
- JptUiPlugin.log(e);
- }
- return Status.OK_STATUS;
- }
- };
- return job;
- }
-
- protected JpaXmlResource getOrmXmlResource(CreateEntityTemplateModel model, IProject project) {
- if (model.isMappingXMLDefault()) {
- return JptCorePlugin.getJpaProject(project).getDefaultOrmXmlResource();
- }
- return JptCorePlugin.getJpaProject(project).getMappingFileXmlResource(model.getMappingXMLName());
- }
-
- /**
- * Adds mapped superclass to ORM XML in separate job
- *
- * @param model entity data model
- * @param project JPA project in which the entity will be created
- * @return the created job
- */
- private Job addMappedSuperclassToXML(final CreateEntityTemplateModel model, final IProject project) {
- Job job = new Job(EntityWizardMsg.ADD_MAPPED_SUPERCLASS_TO_XML) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- final JpaXmlResource xmlResource = getOrmXmlResource(model, project);
- EntityMappings entityMappings = (EntityMappings) JptCorePlugin.getJpaProject(project).getJpaFile(xmlResource.getFile()).rootStructureNodes().next();
- OrmPersistentType persistentType = entityMappings.addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, model.getQualifiedJavaClassName());
- MappedSuperclass mappedSuperclass = (MappedSuperclass) persistentType.getMapping();
-
- if (model.isCompositePK()) {
- mappedSuperclass.setIdClass(model.getIdClassName());
- }
-
- for (String fieldName : model.getPKFields()) {
- persistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, fieldName);
- }
-
- persistentType.setSpecifiedAccess(getModelAccessType(model));
-
- try {
- xmlResource.saveIfNecessary();
- }
- catch (Exception e) {
- JptUiPlugin.log(e);
- }
- return Status.OK_STATUS;
- }
- };
- return job;
- }
-
- protected AccessType getModelAccessType(CreateEntityTemplateModel model) {
- String accessTypeString = FIELD;
- if (!model.isFieldAccess()) {
- accessTypeString = PROPERTY;
- }
- return AccessType.fromOrmResourceModel(OrmFactory.eINSTANCE.createAccessTypeFromString(null, accessTypeString));// TODO
- }
-
- protected InheritanceType getModelInheritanceType(CreateEntityTemplateModel model) {
- String inheritanceStrategy = model.getInheritanceStrategyName();
- if (inheritanceStrategy.equals(EMPTY_STRING)) {
- inheritanceStrategy = SINGLE_TABLE;
- }
- return InheritanceType.fromOrmResourceModel(OrmFactory.eINSTANCE.createInheritanceTypeFromString(null, inheritanceStrategy));//TODO
- }
-
- /**
- * Regist the class in the persistence.xml
- *
- * @param model entity data model
- * @param project JPA project in which the entity will be created
- * @return the created job
- */
- private Job registerClassInPersistenceXml(final CreateEntityTemplateModel model, final IProject project) {
- Job job = new Job(EntityWizardMsg.APPLY_CHANGES_TO_PERSISTENCE_XML) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- final JpaProject jpaProject = JptCorePlugin.getJpaProject(project);
- final JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
- resource.modify(new Runnable() {
- public void run() {
- XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
- EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
- XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support
-
- if (!model.isNonEntitySuperclass()) {
- XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
- classRef.setJavaClass(model.getQualifiedJavaClassName());
- persistenceUnit.getClasses().add(classRef);
- }
- }
- });
-
- return Status.OK_STATUS;
- }
- };
- return job;
-
- }
-
- /**
- * @param input the name of mapping XML from the class wizard page. It is relative path from the source folder
- * and includes META-INF folder
- * @return the simple name of the mapping XML
- */
- private String getLastSegment(String input) {
- String output = input;
- if (input.indexOf(SEPARATOR) != -1) {
- output = input.substring(input.lastIndexOf(SEPARATOR) + 1);
- }
- return output;
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationFigure.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationFigure.java
deleted file mode 100644
index 2599e17366..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationFigure.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.draw2d.Button;
-import org.eclipse.draw2d.ChopboxAnchor;
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.ConnectionEndpointLocator;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.Label;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.PolygonDecoration;
-import org.eclipse.draw2d.PolylineConnection;
-import org.eclipse.draw2d.XYLayout;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-
-
-class AssociationFigure extends Button {
-
- Color enabledColor = new Color( null, 14,66,115);
- Color disabledLineColor = new Color( null, 192,215,231);
- Color selectedColor = new Color( null, 232,232,232 );
-
- Color selectedBorderColor = new Color( null, 14,66,115 );
- LineBorder selectedBorder = new LineBorder( selectedBorderColor, 2 );
- LineBorder unselectedBorder = new LineBorder( ColorConstants.lightGray, 1 );
- Font descriptionFont = new Font(null, "Arial", 8, SWT.NONE);
-
- /**
- * The model behind the the view object
- */
- Association association;
- TableFigure tableFig1;
- TableFigure tableFig2;
- PolylineConnection connection ;
-
- PolygonDecoration referrerDecoration ;
- PolygonDecoration referencedDecoration ;
-
- Label referencedLabel ;
- Label referrerLabel ;
- Label descriptionLabel ;
-
- AssociationFigure(Association association) {
- this.association = association;
-
- XYLayout contentsLayout = new XYLayout();
- setLayoutManager(contentsLayout);
- setBorder( unselectedBorder );
-
- //Create the figures for referrer table and referenced table
- tableFig1 = new TableFigure( association.getReferrerTable().getName() );
- tableFig2 = new TableFigure( association.getReferencedTable().getName() );
-
- contentsLayout.setConstraint(tableFig1, new Rectangle(10,10,150,20));
- contentsLayout.setConstraint(tableFig2, new Rectangle(280, 10, 150, 20));
-
- connection = drawConnection(tableFig1, tableFig2);
-
- add(tableFig1);
- add(tableFig2);
- add(connection);
-
-
- descriptionLabel = new Label("");
- contentsLayout.setConstraint(descriptionLabel, new Rectangle(10,30,-1,-1));
- descriptionLabel.setFont( descriptionFont );
- add(descriptionLabel);
-
- //set white background
- this.setBackgroundColor(ColorConstants.white);
-
- update();
-
- }
-
- private PolylineConnection drawConnection(TableFigure tableFig1,
- TableFigure tableFig2) {
- /* Creating the connection */
- PolylineConnection connection = new PolylineConnection();
- ChopboxAnchor sourceAnchor = new ChopboxAnchor(tableFig1);
- ChopboxAnchor targetAnchor = new ChopboxAnchor(tableFig2);
- connection.setSourceAnchor(sourceAnchor);
- connection.setTargetAnchor(targetAnchor);
-
- /* Creating the decoration */
- referrerDecoration = new SmoothPolygonDecoration();
- connection.setSourceDecoration(referrerDecoration);
-
- referencedDecoration = new SmoothPolygonDecoration();
- connection.setTargetDecoration(referencedDecoration);
-
-
- /* Adding labels to the connection */
- ConnectionEndpointLocator sourceEndpointLocator =
- new ConnectionEndpointLocator(connection, false);
- sourceEndpointLocator.setVDistance(-5);
- referrerLabel = new Label("");
- connection.add(referrerLabel, sourceEndpointLocator);
-
- ConnectionEndpointLocator targetEndpointLocator =
- new ConnectionEndpointLocator(connection, true);
- targetEndpointLocator.setVDistance(-5);
- referencedLabel = new Label("");
- connection.add(referencedLabel, targetEndpointLocator);
-
- ConnectionEndpointLocator relationshipLocator =
- new ConnectionEndpointLocator(connection,true);
- relationshipLocator.setUDistance(10);
- relationshipLocator.setVDistance(-20);
- Label relationshipLabel = new Label("contains");
- connection.add(relationshipLabel,relationshipLocator);
- return connection;
- }
-
- public Association getAssociation() {
- return this.association;
- }
-
- public void setSelected ( boolean isSelected ){
- this.setBackgroundColor( isSelected ? selectedColor : ColorConstants.white );
- this.setBorder(isSelected? selectedBorder : unselectedBorder);
- }
-
- /**
- * Update the view with the changes user made on the model
- */
- public void update(){
- boolean isGenerated = association.isGenerated();
-
- connection.setForegroundColor( isGenerated? enabledColor: disabledLineColor );
-
- tableFig1.setEnabled(isGenerated);
- tableFig2.setEnabled(isGenerated);
- descriptionLabel.setForegroundColor(isGenerated? enabledColor: disabledLineColor);
-
- //paintDirectionalityAndCardinality
- String cardinalityStr;
- String directionality = association.getDirectionality();
- String cardinality = association.getCardinality();
- //Draw referrerRole
- if (cardinality.equals(Association.MANY_TO_ONE) || cardinality.equals(Association.MANY_TO_MANY)) {
- cardinalityStr = "*";
- } else {
- cardinalityStr = "1";
- }
- if (directionality.equals(Association.BI_DI) || directionality.equals(Association.OPPOSITE_DI)) {
- connection.setSourceDecoration(this.referrerDecoration);
- }else{
- connection.setSourceDecoration(null);
- }
-
- this.referrerLabel.setText( cardinalityStr );
-
- //Draw referencedRole
- if (cardinality.equals(Association.MANY_TO_ONE) || cardinality.equals(Association.ONE_TO_ONE)) {
- cardinalityStr = "1";
- } else {
- cardinalityStr = "*";
- }
- if (directionality.equals(Association.BI_DI) || directionality.equals(Association.NORMAL_DI)) {
- connection.setTargetDecoration(this.referencedDecoration);
- }else{
- connection.setTargetDecoration(null);
- }
- this.referencedLabel.setText(cardinalityStr);
-
- String text = "";
- String referrerTableName = association.getReferrerTableName();
- String referencedTable = association.getReferencedTableName();
- if( cardinality.equals(Association.MANY_TO_ONE ) ){
- text = String.format( JptUiEntityGenMessages.manyToOneDesc, referencedTable , referrerTableName );
- }else if( cardinality.equals(Association.ONE_TO_ONE ) ){
- text = String.format( JptUiEntityGenMessages.oneToOneDesc, referrerTableName, referencedTable );
- }else if( cardinality.equals(Association.MANY_TO_MANY) ){
- text = String.format( JptUiEntityGenMessages.manyToManyDesc, referrerTableName, referencedTable, referencedTable, referrerTableName );
- }
-
- if( association.isCustom() ){
- connection.setLineStyle( SWT.LINE_DOT);
- }
-
- this.descriptionLabel.setText(text);
-
- }
-
- public class SmoothPolygonDecoration extends PolygonDecoration
- {
- public SmoothPolygonDecoration()
- {
- super();
- }
-
- @Override
- public void paintFigure(Graphics graphics)
- {
- int savedAntialias = graphics.getAntialias();
- graphics.setAntialias(SWT.ON);
- super.paintFigure(graphics);
- graphics.setAntialias(savedAntialias);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationTablesPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationTablesPage.java
deleted file mode 100644
index d73dfcd744..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationTablesPage.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.createButton;
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.createLabel;
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.createText;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Text;
-
-
-
-public class AssociationTablesPage extends NewAssociationWizardPage {
-
- private Button simpleAssoBtn;
- private Button mtmAssoBtn;
- private Text table1TextField ;
- private Text table2TextField ;
- private Text joinTableTextField;
- private Button joinTableBrowse;
-
- public AssociationTablesPage(ORMGenCustomizer customizer) {
- super(customizer, "AssociationTablesPage");
- setTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_title);
- setDescription(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_desc);
- }
-
- public void createControl(Composite composite) {
- initializeDialogUnits(composite);
- Composite parent = new Composite(composite, SWT.NONE);
- parent.setLayout(new GridLayout(1, true));
-
- Group assocKindGroup = new Group(parent, SWT.NULL);
- int nColumns= 3 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- assocKindGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- assocKindGroup.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_ASSOCIATION_TABLES);
- assocKindGroup.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_assocKind);
-
- simpleAssoBtn = createButton(assocKindGroup, 3, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_simpleAssoc, SWT.RADIO);
- mtmAssoBtn = createButton(assocKindGroup, 3, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_m2mAssoc, SWT.RADIO);
-
-
- Group assocTablesGroup = new Group(parent, SWT.NULL);
- nColumns= 3 ;
- layout = new GridLayout();
- layout.numColumns = nColumns;
- assocTablesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- assocTablesGroup.setLayout(layout);
-
-
- assocTablesGroup.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_assocTables );
-
- createLabel(assocTablesGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_table1);
- table1TextField = createText(assocTablesGroup, 1);
-
- Button browser1 = createButton(assocTablesGroup, 1, "", SWT.NONE);
- browser1.setImage( ImageRepository.getBrowseButtonImage());
-
- browser1.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- SelectTableDialog dlg = new SelectTableDialog( Display.getDefault().getActiveShell(), customizer.getTableNames() );
- if( dlg.open() ==Dialog.OK ){
- table1TextField.setText( dlg.getSelectedTable() );
- getWizardDataModel().put( NewAssociationWizard.ASSOCIATION_REFERRER_TABLE, table1TextField.getText());
- getWizard().getContainer().updateButtons();
- ((NewAssociationWizard)getWizard()).updateTableNames();
- }
- }
- });
-
- createLabel(assocTablesGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_table2);
- table2TextField = createText(assocTablesGroup, 1);
-
- Button browser2 = createButton(assocTablesGroup, 1, "", SWT.NONE);
- browser2.setImage( ImageRepository.getBrowseButtonImage());
-
- browser2.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- SelectTableDialog dlg = new SelectTableDialog( Display.getDefault().getActiveShell(), customizer.getSchema() );
- if( dlg.open() == Dialog.OK){
- table2TextField.setText( dlg.getSelectedTable() );
- getWizardDataModel().put( NewAssociationWizard.ASSOCIATION_REFERENCED_TABLE, table2TextField.getText());
- ((NewAssociationWizard)getWizard()).updateTableNames();
- }
- updatePageComplete();
- }
- });
-
- createLabel(assocTablesGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_tablesPage_intermediateTable );
- joinTableTextField = createText(assocTablesGroup, 1);
- joinTableTextField.setEnabled(false);
-
- joinTableBrowse = createButton(assocTablesGroup, 1, "", SWT.NONE);
- joinTableBrowse.setImage( ImageRepository.getBrowseButtonImage());
- joinTableBrowse.setEnabled(false);
-
- joinTableBrowse.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- SelectTableDialog dlg = new SelectTableDialog( Display.getDefault().getActiveShell(), customizer.getSchema() );
- if( dlg.open() == Dialog.OK){
- joinTableTextField.setText( dlg.getSelectedTable() );
- getWizardDataModel().put( NewAssociationWizard.ASSOCIATION_JOIN_TABLE, joinTableTextField.getText() );
- ((NewAssociationWizard)getWizard()).updateTableNames();
- getWizard().getContainer().updateButtons();
- }
- updatePageComplete();
- }
- });
-
- setControl(parent);
-
- simpleAssoBtn.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- joinTableTextField.setEnabled(false);
- joinTableTextField.clearSelection();
- joinTableTextField.setText("");
- joinTableBrowse.setEnabled(false);
- getWizardDataModel().put( NewAssociationWizard.ASSOCIATION_CADINALITY, Association.MANY_TO_ONE);
- getWizardDataModel().remove( NewAssociationWizard.ASSOCIATION_JOIN_TABLE );
- ((NewAssociationWizard)getWizard()).updateTableNames();
- updatePageComplete();
- }
-
- });
-
- mtmAssoBtn.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- joinTableTextField.setEnabled(true);
- joinTableBrowse.setEnabled(true);
- getWizardDataModel().put( NewAssociationWizard.ASSOCIATION_CADINALITY, Association.MANY_TO_MANY);
- ((NewAssociationWizard)getWizard()).updateTableNames();
- updatePageComplete();
- }
- });
-
- this.setPageComplete( false);
- table1TextField.setFocus();
- }
-
- public boolean canFlipToNextPage() {
- return isPageComplete();
- }
-
- public void updatePageComplete() {
- if( this.table1TextField.getText().length() <= 0){
- setPageComplete(false);
- return;
- }
- if( mtmAssoBtn.getSelection() ){
- if( this.joinTableTextField.getText().length() <= 0 ){
- setPageComplete(false);
- return;
- }
- }
- setPageComplete(true);
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationsListComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationsListComposite.java
deleted file mode 100644
index fc92e30eb8..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/AssociationsListComposite.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.List;
-
-import org.eclipse.draw2d.ActionEvent;
-import org.eclipse.draw2d.ActionListener;
-import org.eclipse.draw2d.Figure;
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.ToolbarLayout;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * A Draw2d figure representing list of associations between two database tables
- *
- */
-public class AssociationsListComposite extends FigureCanvas {
-
- List<Association> associations;
- AssociationToggleSelectionListener listener ;
- TableAssociationsWizardPage tableAssociationsWizardPage; //the parent wizard page
- AssociationFigure selectedAssociationFigure ;
-
- public AssociationsListComposite(Composite parent, TableAssociationsWizardPage tableAssociationsWizardPage){
- super(parent);
- this.tableAssociationsWizardPage = tableAssociationsWizardPage;
-
- setBounds(10, 10 , 500, 200);
- setBackground( new Color(Display.getDefault(), 255,255,255));
-
- Figure figure = new Figure();
- figure.setLayoutManager(new ToolbarLayout());
- figure.setBorder(new LineBorder(1));
- this.listener = new AssociationToggleSelectionListener();
-
- this.setContents(figure);
- }
-
- @SuppressWarnings("unchecked")
- public void updateAssociations(List<Association> associations){
- Figure figure = (Figure)this.getContents();
- List<AssociationFigure> associationFigures = figure.getChildren();
- for(AssociationFigure assocFig : associationFigures){
- assocFig.removeActionListener(listener);
- }
- figure.removeAll();
- this.selectedAssociationFigure = null;
-
- this.associations = associations;
- if( associations != null ){
- for( int i = 0; i <associations.size(); i ++ ){
- Association association = associations.get(i);
- AssociationFigure assocFigure = new AssociationFigure(association);
- assocFigure.addActionListener( listener );
- figure.add(assocFigure);
- }
- }
- }
-
- public Association getSelectedAssociation(){
- return this.selectedAssociationFigure.getAssociation();
- }
-
- @SuppressWarnings("unchecked")
- public void updateSelectedAssociation(){
- Figure figure = (Figure)this.getContents();
- List<AssociationFigure> associationFigures = figure.getChildren();
- for(AssociationFigure assocFig : associationFigures){
- if( assocFig == this.selectedAssociationFigure){
- assocFig.update();
- }
- }
- }
-
- /**
- * Get the association just before the selected one in UI
- * @return
- */
- @SuppressWarnings("unchecked")
- public Association getPreviousAssociation(){
- Figure figure = (Figure)this.getContents();
- List<AssociationFigure> associationFigures = figure.getChildren();
- AssociationFigure ret = null;
- for(AssociationFigure assocFig : associationFigures){
- if( assocFig.isSelected() ){
- break;
- }
- ret = assocFig;
- }
- return ret==null?null:ret.getAssociation();
- }
-
- class AssociationToggleSelectionListener implements ActionListener {
- public void actionPerformed(ActionEvent event) {
- AssociationFigure figure = (AssociationFigure )event.getSource() ;
- figure.setSelected(true);
- Association association = figure.getAssociation();
- tableAssociationsWizardPage.updateAssociationEditPanel(association);
- //un-select the previous selected
- if( selectedAssociationFigure != null && selectedAssociationFigure!= figure ){
- selectedAssociationFigure.setSelected( false );
- }
- //Highlight new selection
- selectedAssociationFigure = figure;
- selectedAssociationFigure.setSelected( true );
-
- }
-
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CardinalityPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CardinalityPage.java
deleted file mode 100644
index 45c9aad968..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CardinalityPage.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-
-
-public class CardinalityPage extends NewAssociationWizardPage {
-
- private Label mtoDescLabel;
- private Label otmDescLabel;
- private Label otoDescLabel;
- private Label mtmDescLabel;
-
- private Button[] cardinalityButtons = new Button[4];
-
- protected CardinalityPage(ORMGenCustomizer customizer) {
- super( customizer , "CardinalityPage" );
- setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_cardinalityPage_title);
- setDescription( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_cardinalityPage_desc);
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
-
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 1 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_ASSOCIATION_CARDINALITY);
-
- CardinalitySelectionListener selectionListener = new CardinalitySelectionListener();
- cardinalityButtons[0] = createRadioButton( composite, 1, JptUiEntityGenMessages.manyToOne);
- cardinalityButtons[0].addSelectionListener( selectionListener );
- //Default cardinality is MTO
- cardinalityButtons[0].setSelection(true);
- getWizardDataModel().put(NewAssociationWizard.ASSOCIATION_CADINALITY, Association.MANY_TO_ONE);
-
- mtoDescLabel = createLabel(composite,1, JptUiEntityGenMessages.manyToOneDesc);
-
- cardinalityButtons[1] = createRadioButton( composite, 1, JptUiEntityGenMessages.oneToMany);
- cardinalityButtons[1].addSelectionListener( selectionListener );
-
- otmDescLabel = createLabel(composite,1, JptUiEntityGenMessages.manyToOneDesc);
-
- cardinalityButtons[2] = createRadioButton( composite, 1, JptUiEntityGenMessages.oneToOne);
- cardinalityButtons[2].addSelectionListener( selectionListener );
-
- otoDescLabel = createLabel(composite,1, JptUiEntityGenMessages.oneToOneDesc);
-
- cardinalityButtons[3] = createRadioButton( composite, 1, JptUiEntityGenMessages.manyToMany);
- mtmDescLabel= createLabel(composite,1, JptUiEntityGenMessages.manyToManyDesc);
-
- setControl(composite);
- this.setPageComplete( true );
-
- cardinalityButtons[0].setFocus();
-
- }
-
- public void updateWithNewTables() {
- String s1 = getReferrerTableName() ;
- String s2 = getReferencedTableName() ;
- String joinTableName = getJoinTableName();
- if( s1 == null || s2 == null )
- return ;
-
- updateDescriptionText(s1, s2);
- if( joinTableName == null ){
- cardinalityButtons[0].setEnabled(true);
- cardinalityButtons[1].setEnabled(true);
- cardinalityButtons[2].setEnabled(true);
- cardinalityButtons[3].setEnabled(false);
- mtmDescLabel.setEnabled(false);
- }else{
- cardinalityButtons[0].setEnabled(false);
- cardinalityButtons[1].setEnabled(false);
- cardinalityButtons[2].setEnabled(false);
- cardinalityButtons[3].setEnabled(true);
- cardinalityButtons[3].setSelection(true);
- mtmDescLabel.setEnabled(true);
- }
- ((Composite)this.getControl()).layout() ;
- }
-
- private void updateDescriptionText(String s1, String s2) {
- //MTO
- String msg = String.format(JptUiEntityGenMessages.manyToOneDesc, s2, s1);
- mtoDescLabel.setText( msg );
- //OTM
- msg = String.format(JptUiEntityGenMessages.manyToOneDesc, s1, s2);
- otmDescLabel.setText( msg );
- msg = String.format(JptUiEntityGenMessages.oneToOneDesc, s1, s2);
- otoDescLabel.setText( msg );
- msg = String.format(JptUiEntityGenMessages.manyToManyDesc, s1, s2, s2, s1);
- mtmDescLabel.setText( msg );
- }
-
- public boolean canFlipToNextPage() {
- return false;
- }
-
- private Label createLabel(Composite container, int span, String text) {
- Label label = new Label(container, SWT.NONE);
- label.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- gd.horizontalIndent = 30;
- label.setLayoutData(gd);
- return label;
- }
-
-
- private Button createRadioButton(Composite container, int span, String text ) {
- Button btn = new Button(container, SWT.RADIO );
- btn.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- btn.setLayoutData(gd);
- return btn;
- }
-
-
- private class CardinalitySelectionListener implements SelectionListener {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- if( e.getSource() == cardinalityButtons[0]){
- getWizardDataModel().put(NewAssociationWizard.ASSOCIATION_CADINALITY, Association.MANY_TO_ONE);
- }else if( e.getSource() == cardinalityButtons[1]){
- getWizardDataModel().put(NewAssociationWizard.ASSOCIATION_CADINALITY, Association.ONE_TO_MANY );
- }else if( e.getSource() == cardinalityButtons[2]){
- getWizardDataModel().put(NewAssociationWizard.ASSOCIATION_CADINALITY, Association.ONE_TO_ONE);
- }else{
- getWizardDataModel().put(NewAssociationWizard.ASSOCIATION_CADINALITY, Association.MANY_TO_MANY);
- }
- CardinalityPage.this.setPageComplete(true);
-
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CascadeDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CascadeDialog.java
deleted file mode 100644
index f4b6a1bd15..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/CascadeDialog.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.TrayDialog;
-import org.eclipse.jpt.gen.internal.AssociationRole;
-import org.eclipse.jpt.gen.internal.util.StringUtil;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-/**
- * Simple dialog allows user to set the cascade property of an associationRole.
- * The value of cascade can be "all", or any combination of other selections.
- *
- */
-public class CascadeDialog extends TrayDialog {
-
- private static String[] ALL_CASCADES = new String[] {TagNames.ALL_CASCADE, TagNames.PERSIST_CASCADE, TagNames.MERGE_CASCADE
- , TagNames.REMOVE_CASCADE, TagNames.REFRESH_CASCADE};
-
- private static String[] ALL_CASCADES_LABELS
- = new String[] { "&all", //$NON-NLS-1$
- "&persist", //$NON-NLS-1$
- "&merge", //$NON-NLS-1$
- "&remove", //$NON-NLS-1$
- "r&efresh"}; //$NON-NLS-1$
-
-
- private Button[] allButtons = new Button[ALL_CASCADES.length];
-
- private AssociationRole associationRole;
- private List<String> cascades;
-
- protected CascadeDialog(Shell parentShell) {
- super(parentShell);
- }
-
- public static CascadeDialog create(AssociationRole role) {
- CascadeDialog dlg = new CascadeDialog(Display.getDefault().getActiveShell() );
- dlg.setAssociationRole(role);
- return dlg;
- }
-
- /*
- * (non-Javadoc) Method declared on Window.
- */
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(JptUiEntityGenMessages.selectCascadeDlgTitle);
- this.getHelpSystem().setHelp(newShell, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_SELECT_CASCADE);
- }
-
- private void setAssociationRole(AssociationRole role) {
- this.associationRole = role;
- List<String> list = StringUtil.strToList(associationRole.getCascade(), ',', true/*trim*/); //role.getCascade() contains the comma separed cascades (see below)
- if (list == null) {
- list = Collections.emptyList();
- }
- cascades = list;
-
- }
-
- protected void createButtonsForButtonBar(Composite parent) {
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
- createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
- }
-
- protected Control createDialogArea(Composite parent) {
- Composite container = (Composite) super.createDialogArea(parent);
- createCascadeTypesGroup(container);
- Dialog.applyDialogFont(container);
- return container;
- }
-
- private void createCascadeTypesGroup(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- group.setLayout(new GridLayout());
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.widthHint = 275;
- group.setLayoutData(gd);
- group.setText(JptUiEntityGenMessages.cascade);
-
- for( int i=0; i< ALL_CASCADES.length; i ++ ){
- Button checkbox = new Button(group, SWT.CHECK);
- checkbox.setText( ALL_CASCADES_LABELS[i] );
- checkbox.setSelection( isInList(ALL_CASCADES[i]) ); //$NON-NLS-1$
- checkbox.setData(ALL_CASCADES[i]);
- allButtons[i] = checkbox;
- /*if <code>all</code> is selected then deselect all others*/
- checkbox.addSelectionListener( new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- Button b = (Button)e.getSource();
- if( b.getSelection() ){
- if( b == allButtons[0] ){
- for( Button btn : allButtons ){
- if( btn != e.getSource() ) btn.setSelection(false);
- }
- }else{
- allButtons[0].setSelection(false);
- }
- }
- }
- });
- }
- }
-
- protected void okPressed() {
- StringBuilder builder = new StringBuilder();
- for( Button b : allButtons ){
- if( b.getSelection() ){
- if( builder.length()>0 ){
- builder.append( ',');
- }
- builder.append( b.getData() );
- }
- }
- this.associationRole.setCascade( builder.toString() );
- super.okPressed();
- }
-
- private boolean isInList(String cascade) {
- for( String s : cascades ){
- if( s.equals(cascade )){
- return true;
- }
- }
- return false;
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-
-}
-
-class TagNames
-{
- public static final String BASIC_TAG = "basic";
- public static final String CASCADE_TAG = "cascade";
- public static final String COLUMN_TAG = "column";
- public static final String EMBEDDED_TAG = "embedded";
- public static final String EMBEDDED_ID_TAG = "embedded-id";
- public static final String GENERATED_VALUE_TAG = "generated-value";
- public static final String ID_TAG = "id";
- public static final String ID_CLASS_TAG = "id";
- public static final String JOIN_COLUMN_TAG = "join-column";
- public static final String INVERSE_JOIN_COLUMN_TAG = "inverse-join-column";
- public static final String LOB_TAG = "lob";
- public static final String MANY_TO_MANY_TAG = "many-to-many";
- public static final String MANY_TO_ONE_TAG = "many-to-one";
- public static final String MAPPED_BY_TAG = "mapped-by";
- public static final String ONE_TO_MANY_TAG = "one-to-many";
- public static final String ONE_TO_ONE_TAG = "one-to-one";
- public static final String PK_JOIN_COLUMN_TAG = "primary-key-join-column";
- public static final String TABLE_TAG = "table";
- public static final String VERSION_TAG = "version";
- public static final String JOIN_TABLE_TAG = "join-table";
-
- /*cascade tags*/
- public static final String ALL_CASCADE = "all";
- public static final String PERSIST_CASCADE = "persist";
- public static final String MERGE_CASCADE = "merge";
- public static final String REMOVE_CASCADE = "remove";
- public static final String REFRESH_CASCADE = "refresh";
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/ColumnGenPanel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/ColumnGenPanel.java
deleted file mode 100644
index 4fe34bf14c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/ColumnGenPanel.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.gen.internal.ORMGenColumn;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-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.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * The panel used in the <code>TablesAndColumnsPage</code> wizard page
- * to edit the column generation properties.
- * An instance of this class is created by the <code>ORMGenWizard</code>
- * implementation.
-
- */
-public class ColumnGenPanel
-{
- WizardPage wizardPage ;
- Composite parent; //parent control with grid layout
- int columns; //total columns in the parent composite
-
- ORMGenCustomizer customizer;
-
- private ORMGenColumn mColumn;
- private boolean mPanelInited;
- private boolean mIsUpdatingControls;
-
- private Group columnMappingGroup;
- private Button mGeneratedCheckbox;
- private Text mPropNameField;
- private Combo mMappingKindCombo;
- private Combo mPropTypeCombo;
- private Button mUpdateableCheckBox;
- private Button mInsertableCheckBox;
-
- private Group domainClassGroup ;
- private ScopePanel mPropGetScopePanel;
- private ScopePanel mPropSetScopePanel;
-
- public ColumnGenPanel(Composite parent, int columns, ORMGenCustomizer customizer, WizardPage wizardPage ) {
- this.wizardPage = wizardPage;
- this.customizer = customizer;
- this.parent =parent;
- this.columns = columns;
-
- initPanel();
- }
- /**
- * Changes the table edited by the panel.
- * This is supposed to update the panel editing controls
- * using the column values.
- */
- public void setColumn(ORMGenColumn column) {
- mColumn = column;
-
- /*lazy init panel because it uses mColumn*/
- if (!mPanelInited) {
- initPanel();
- mPanelInited = true;
- }
-
- updateControls();
- }
- private void updateControls() {
- if (mIsUpdatingControls) {
- return;
- }
-
- mIsUpdatingControls = true;
- boolean isGenerated = mColumn.isGenerated();
- mGeneratedCheckbox.setSelection( isGenerated);
-
- enableControls(isGenerated);
- try {
- mPropNameField.setText(mColumn.getPropertyName());
-
- mPropTypeCombo.setText( mColumn.getPropertyType());
-
- mMappingKindCombo.setText( mColumn.getMappingKind());
-
- mUpdateableCheckBox.setSelection( mColumn.isUpdateable());
-
- mInsertableCheckBox.setSelection(mColumn.isInsertable());
-
- mPropGetScopePanel.enableComponents(isGenerated);
- mPropGetScopePanel.setScope(mColumn.getPropertyGetScope());
-
- mPropSetScopePanel.enableComponents( isGenerated );
- mPropSetScopePanel.setScope(mColumn.getPropertySetScope());
- } catch (Exception e) {
- JptUiPlugin.log(e);
- }
-
- mIsUpdatingControls = false;
- }
- private void enableControls(boolean isGenerated) {
- Control[] controls = this.domainClassGroup.getChildren();
- for( Control c: controls){
- c.setEnabled( isGenerated );
- }
-
- controls = this.columnMappingGroup.getChildren();
- for( Control c: controls){
- c.setEnabled( isGenerated );
- }
- }
- /**
- * Initializes the panel by adding the editing controls.
- * @param columns
- * @param parent
- */
- protected void initPanel() {
- createControls(parent, columns);
- this.mPanelInited = true;
- }
-
- //-------------------------------------------
- //----- ScopePanel class --------------------
- //-------------------------------------------
- /**
- * A panel containing 3 radios (public, protected, private)
- */
- private class ScopePanel
- {
- private Button mPublicRadio;
- private Button mProtectedRadio;
- private Button mPrivateRadio;
-
- public ScopePanel(Composite comp, SelectionListener listener) {
- //super(3, 20/*hspacing*/, 0/*vspacing*/);
-
- Composite radioGroup = new Composite( comp, SWT.NONE);
- radioGroup.setLayout(new GridLayout(3, true));
- GridData gd = new GridData();
- gd.horizontalSpan = 3;
- radioGroup.setLayoutData(gd);
-
- /*string not localized intentionally, they are used as the actual
- * scope value (see getText() usage)*/
- mPublicRadio = new Button( radioGroup, SWT.RADIO );
- mPublicRadio.setText( "public");
- mPublicRadio.setLayoutData(new GridData());
- mProtectedRadio = new Button( radioGroup, SWT.RADIO );
- mProtectedRadio.setText("protected");
- mProtectedRadio.setLayoutData(new GridData());
- mPrivateRadio = new Button(radioGroup, SWT.RADIO );
- mPrivateRadio.setText( "private");
- mPrivateRadio.setLayoutData(new GridData());
-
- mPublicRadio.addSelectionListener(listener);
- mProtectedRadio.addSelectionListener(listener);
- mPrivateRadio.addSelectionListener(listener);
-
- }
- public void enableComponents(boolean b) {
- mPublicRadio.setEnabled(b);
- mProtectedRadio.setEnabled(b);
- mPrivateRadio.setEnabled(b);
- }
- /**
- * Returns the currently selected scope.
- */
- public String getScope() {
- Button radio = null;
- if (mPublicRadio.getSelection()) {
- radio = mPublicRadio;
- } else if (mProtectedRadio.getSelection() ) {
- radio = mProtectedRadio;
- } else if (mPrivateRadio.getSelection() ) {
- radio = mPrivateRadio;
- }
- return radio != null ? radio.getText() : null;
- }
- public void setScope(String scope) {
- mPublicRadio.setSelection(false);
- mProtectedRadio.setSelection(false);
- mPrivateRadio.setSelection(false);
- if( scope == null )
- return;
- if (scope.equals(ORMGenColumn.PUBLIC_SCOPE)) {
- mPublicRadio.setSelection(true);
- } else if (scope.equals(ORMGenColumn.PROTECTED_SCOPE)) {
- mProtectedRadio.setSelection(true);
- } else if (scope.equals(ORMGenColumn.PRIVATE_SCOPE)) {
- mPrivateRadio.setSelection(true);
- }
- }
- }
-
- //-------------------------------------------
- //----- private methods ---------------------
- //-------------------------------------------
- private void createControls(Composite composite, int columns) {
- mGeneratedCheckbox = new Button(composite, SWT.CHECK);
- mGeneratedCheckbox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_genProp);
- mGeneratedCheckbox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- mColumn.setGenerated(mGeneratedCheckbox.getSelection() );
- updateControls();
- }
- }});
- SWTUtil.fillColumns(mGeneratedCheckbox, columns);
-
- columnMappingGroup = new Group( composite, SWT.NONE);
- columnMappingGroup.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_colMapping);
- columnMappingGroup.setLayout(new GridLayout(columns, false));
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- layoutData.horizontalIndent = 20 ;
- columnMappingGroup.setLayoutData(layoutData);
-
- SWTUtil.createLabel(columnMappingGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_propName );
- mPropNameField = new Text(columnMappingGroup, SWT.BORDER | SWT.SINGLE );
- mPropNameField.addModifyListener(new ModifyListener(){
- @SuppressWarnings("restriction")
- public void modifyText(ModifyEvent e) {
- if (!mIsUpdatingControls) {
- String fldName = mPropNameField.getText();
- IStatus status = JavaConventions.validateIdentifier( fldName,
- JavaCore.VERSION_1_3, JavaCore.VERSION_1_3 );
- if( !status.matches(IStatus.ERROR)){
- mColumn.setPropertyName(fldName);
- wizardPage.setErrorMessage(null);
- }else{
- wizardPage.setErrorMessage(status.getMessage());
- }
- }
- }
- });
- SWTUtil.fillColumns(mPropNameField ,3);
-
- SWTUtil.createLabel(columnMappingGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_propType );
- mPropTypeCombo = new Combo(columnMappingGroup, SWT.SINGLE | SWT.READ_ONLY);
- mPropTypeCombo.setItems( this.customizer.getAllPropertyTypes());
- mPropTypeCombo.addModifyListener( new ModifyListener(){
- public void modifyText(ModifyEvent e) {
- if (!mIsUpdatingControls) {
- mColumn.setPropertyType(mPropTypeCombo.getText());
- }
- }
- });
- SWTUtil.fillColumns(mPropTypeCombo,3);
-
- SWTUtil.createLabel(columnMappingGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_mapKind );
- mMappingKindCombo = new Combo(columnMappingGroup, SWT.SINGLE | SWT.READ_ONLY);
- mMappingKindCombo.setItems( this.customizer.getAllMappingKinds());
- mMappingKindCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- mColumn.setMappingKind((String)mMappingKindCombo.getText());
- }
-
- }});
- SWTUtil.fillColumns(mMappingKindCombo ,3);
-
- mUpdateableCheckBox = new Button(columnMappingGroup, SWT.CHECK);
- mUpdateableCheckBox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_colUpdateable);
- mUpdateableCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- mColumn.setUpdateable(mUpdateableCheckBox.getSelection() );
- }
- }});
- SWTUtil.fillColumns(mUpdateableCheckBox ,4);
-
- mInsertableCheckBox = new Button(columnMappingGroup, SWT.CHECK);
- mInsertableCheckBox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_colInsertable);
- mInsertableCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- mColumn.setInsertable(mInsertableCheckBox.getSelection());
- }
- }});
- SWTUtil.fillColumns(mInsertableCheckBox ,4);
-
- SWTUtil.createLabel(composite, 4,"");
-
- createJavaBeanPropertyControls(composite, columns);
- }
-
- void createJavaBeanPropertyControls(Composite composite, int columns){
- //Java class generation properties
- domainClassGroup = new Group(composite, SWT.NONE);
- domainClassGroup.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_beanProp );
- domainClassGroup.setLayout(new GridLayout(columns, false));
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- layoutData.horizontalIndent = 20;
- domainClassGroup.setLayoutData(layoutData);
-
- SWTUtil.createLabel(domainClassGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_getterScope );
- mPropGetScopePanel = new ScopePanel(domainClassGroup, new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- if( ((Button)e.getSource()).getSelection() )
- mColumn.setPropertyGetScope(mPropGetScopePanel.getScope());
- }
-
- }});
-
- SWTUtil.createLabel(domainClassGroup, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_colPanel_setterScope );
- mPropSetScopePanel = new ScopePanel(domainClassGroup, new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- if (!mIsUpdatingControls) {
- if( ((Button)e.getSource()).getSelection() )
- mColumn.setPropertySetScope(mPropSetScopePanel.getScope());
- }
- }});
-
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java
deleted file mode 100644
index 925134b8a5..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java
+++ /dev/null
@@ -1,518 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-import java.util.EventListener;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.SortedSet;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.db.ConnectionAdapter;
-import org.eclipse.jpt.db.ConnectionListener;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.JptDbPlugin;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.SchemaContainer;
-import org.eclipse.jpt.db.ui.internal.DTPUiTools;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-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.Display;
-import org.eclipse.swt.widgets.Label;
-
-/**
- * A composite used to connect to database, includes following UI controls:
- * - connection combo-box
- * - schema combo-box
- * - add connection button
- * - reconnect button
- */
-public class DatabaseGroup
-{
- private final JpaProject jpaProject;
- private final Set<Listener> listeners = Collections.synchronizedSet(new HashSet<Listener>());
-
- // these are kept in synch with the selection
- ConnectionProfile selectedConnectionProfile;
- private Schema selectedSchema;
-
- private final Combo connectionComboBox;
-
- private final Combo schemaComboBox;
-
- private final Button reconnectButton;
-
- private final ConnectionListener connectionListener;
-
- private IWizardContainer wizardContainer;
-
- // ********** construction **********
-
- DatabaseGroup(IWizardContainer wizardContainer, JpaProject jpaProject, Composite parent, int widthHint)
- {
- super();
- this.wizardContainer = wizardContainer;
- this.jpaProject = jpaProject;
-
- // connection combo-box
- this.buildLabel(parent, 1, JptUiEntityGenMessages.connection);
- this.connectionComboBox = this.buildComboBox(parent, widthHint, this.buildConnectionComboBoxSelectionListener());
-
- // add connection button
- this.buildButton(parent, JptUiEntityGenMessages.addConnectionLink, ImageRepository.getAddConnectionButtonImage(), this.buildAddConnectionLinkSelectionListener());
-
- // A composite holds the reconnect button & text
- this.buildLabel(parent, 1, ""); //$NON-NLS-1$
- Composite comp = new Composite( parent , SWT.NONE );
- GridData gd = new GridData();
- gd.grabExcessHorizontalSpace = true ;
- gd.horizontalSpan = 2;
- comp.setLayoutData( gd );
- GridLayout gl = new GridLayout(2, false);
- // Make the reconnect button to be closer to the connection combo.
- gl.marginTop = -5;
- comp.setLayout(gl);
- this.reconnectButton = this.buildButton(comp, JptUiEntityGenMessages.connectLink, ImageRepository.getReconnectButtonImage(), this.buildReconnectLinkSelectionListener());
- this.buildLabel(comp, 1, JptUiEntityGenMessages.schemaInfo);
-
- // schema combo-box
- this.buildLabel(parent, 1, JptUiEntityGenMessages.schema);
- this.schemaComboBox = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- GridData data = new GridData(SWT.BEGINNING, SWT.CENTER, true, false);
- data.horizontalAlignment = SWT.FILL;
- data.horizontalSpan = 1;
- data.grabExcessHorizontalSpace = true ;
- this.schemaComboBox.setLayoutData(data);
- this.schemaComboBox.addSelectionListener(this.buildSchemaComboBoxSelectionListener());
- // filler
- new Label(parent, SWT.NULL);
-
- this.connectionListener = this.buildConnectionListener();
- }
-
-
- public void init()
- {
- // initialize state, based on JPA project
- this.selectedConnectionProfile = this.getJpaProjectConnectionProfile();
- this.selectedSchema = this.getDefaultSchema();
-
- if (this.selectedSchema != null) {
- this.fireSchemaChanged(this.selectedSchema);
- }
- if (this.selectedConnectionProfile != null) {
- this.selectedConnectionProfile.addConnectionListener(this.connectionListener);
- this.fireConnectionProfileChanged(this.selectedConnectionProfile);
- }
-
- this.updateConnectionComboBox();
- this.updateSchemaComboBox();
- this.updateReconnectLink();
-
- }
- // ********** intra-wizard methods **********
-
- Schema getSelectedSchema() {
- return this.selectedSchema;
- }
-
- void dispose() {
- if (this.selectedConnectionProfile != null) {
- this.selectedConnectionProfile.removeConnectionListener(this.connectionListener);
- }
- }
-
-
- // ********** internal methods **********
-
- /**
- * this can return null;
- * called at start-up and when the selected connection profile changes
- */
- private ConnectionProfile getJpaProjectConnectionProfile() {
- return this.jpaProject.getConnectionProfile();
- }
-
- /**
- * this can return null;
- * called at start-up and when the selected connection profile changes
- */
- private Schema getDefaultSchema() {
- return (this.selectedConnectionProfile == this.getJpaProjectConnectionProfile()) ?
- jpaProject.getDefaultDbSchema() : null;
- }
-
- /**
- * the connection combo-box is updated at start-up and when the user
- * adds a connection profile
- */
- private void updateConnectionComboBox() {
- this.connectionComboBox.removeAll();
- for (String cpName : this.buildSortedConnectionProfileNames()) {
- this.connectionComboBox.add(cpName);
- }
- if (this.selectedConnectionProfile != null) {
- this.connectionComboBox.select(this.connectionComboBox.indexOf(this.selectedConnectionProfile.getName()));
- }
- }
-
- private SortedSet<String> buildSortedConnectionProfileNames() {
- return CollectionTools.sortedSet(JptDbPlugin.instance().getConnectionProfileFactory().connectionProfileNames());
- }
-
- /**
- * called at start-up and when the selected connection profile changes
- */
- private void updateReconnectLink() {
- this.reconnectButton.setEnabled(this.reconnectLinkCanBeEnabled());
- }
-
- private boolean reconnectLinkCanBeEnabled() {
- return (this.selectedConnectionProfile != null) && !(this.selectedConnectionProfile.isActive());
- }
-
- /**
- * the schema combo-box is updated at start-up and
- * when the selected connection profile changes
- */
- private void updateSchemaComboBox() {
- this.schemaComboBox.removeAll();
- for (Iterator<String> stream = this.schemaNames(); stream.hasNext(); ) {
- this.schemaComboBox.add(stream.next());
- }
- // the current schema *should* be in the current connection profile
- if (this.selectedSchema != null) {
- this.schemaComboBox.select(this.schemaComboBox.indexOf(this.selectedSchema.getName()));
- }
- }
-
- private Iterator<String> schemaNames() {
- SchemaContainer sc = this.jpaProject.getDefaultDbSchemaContainer();
- // use schema *names* since the combo-box is read-only
- return (sc != null) ? sc.sortedSchemaNames() : EmptyIterator.<String>instance();
- }
-
- /**
- * If the specified name matches the name of the JPA project's
- * connection profile, return it; otherwise, build a new connection
- * profile.
- */
- private ConnectionProfile checkJpaProjectConnectionProfile(String cpName) {
- ConnectionProfile cp = this.getJpaProjectConnectionProfile();
- if ((cp != null) && cp.getName().equals(cpName)) {
- return cp;
- }
- return this.buildConnectionProfile(cpName);
- }
-
- private ConnectionProfile buildConnectionProfile(String name) {
- return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(name);
- }
-
-
- // ********** listener callbacks **********
-
- void selectedConnectionChanged() {
- String text = this.connectionComboBox.getText();
- if (text.length() == 0) {
- if (this.selectedConnectionProfile == null) {
- return; // no change
- }
- this.selectedConnectionProfile.removeConnectionListener(this.connectionListener);
- this.selectedConnectionProfile = null;
- } else {
- if (this.selectedConnectionProfile == null) {
- this.selectedConnectionProfile = this.checkJpaProjectConnectionProfile(text);
- } else {
- if (text.equals(this.selectedConnectionProfile.getName())) {
- return; // no change
- }
- this.selectedConnectionProfile.removeConnectionListener(this.connectionListener);
- this.selectedConnectionProfile = this.checkJpaProjectConnectionProfile(text);
- }
- this.selectedConnectionProfile.addConnectionListener(this.connectionListener);
- }
- this.fireConnectionProfileChanged(this.selectedConnectionProfile);
- this.connectionChanged();
- }
-
- void selectedSchemaChanged() {
- Schema old = this.selectedSchema;
- this.selectedSchema = this.jpaProject.getDefaultDbSchemaContainer().getSchemaNamed(this.schemaComboBox.getText());
- if (this.selectedSchema != old) {
- fireSchemaChanged(this.selectedSchema);
- }
- }
-
- /**
- * Open the DTP New Connection Profile wizard.
- * If the user creates a new connection profile, start using it and
- * connect it
- */
- void addConnection() {
- String addedProfileName = DTPUiTools.createNewConnectionProfile();
- if (addedProfileName == null) {
- return; // user pressed "Cancel"
- }
- if (this.selectedConnectionProfile != null) {
- this.selectedConnectionProfile.removeConnectionListener(this.connectionListener);
- }
- this.selectedConnectionProfile = this.buildConnectionProfile(addedProfileName);
- this.selectedConnectionProfile.addConnectionListener(this.connectionListener);
- this.updateConnectionComboBox();
- this.selectedConnectionProfile.connect();
- this.updateSchemaComboBox();
- // everything else should be synchronized when we get the resulting open event
- this.fireConnectionProfileChanged(this.selectedConnectionProfile);
- }
-
- void reconnect() {
- try {
- wizardContainer.run(true, true, new IRunnableWithProgress(){
- public void run( final IProgressMonitor monitor )
- throws InvocationTargetException, InterruptedException
- {
- monitor.beginTask(JptUiEntityGenMessages.connectingToDatabase, 10);
- final boolean[] isConnected= new boolean[1];
- isConnected[0]=false;
- Thread t= new Thread(){
- @Override
- public void run() {
- try {
- DatabaseGroup.this.selectedConnectionProfile.connect();
- } catch (Exception ex) {
- // huh?
- }
- isConnected[0]=true;
- }
- };
- t.start();
- while( !isConnected[0] ){
- Thread.sleep(1000);
- monitor.worked(1);
- }
- // everything should be synchronized when we get the resulting open event
- monitor.done();
- }
- });
- } catch (Exception e) {
- JptUiPlugin.log(e);
- }
- }
-
- /**
- * called when
- * - the user selects a new connection
- * - the connection was opened
- * - the connection was closed (never happens?)
- * we need to update the schema stuff and the reconnect link
- */
- void connectionChanged() {
- Schema old = this.selectedSchema;
- this.selectedSchema = this.getDefaultSchema();
- if (this.selectedSchema != old) {
- this.fireSchemaChanged(this.selectedSchema);
- }
- this.updateSchemaComboBox();
- this.updateReconnectLink();
- }
-
-
- // ********** listeners **********
-
- private SelectionListener buildConnectionComboBoxSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.selectedConnectionChanged();
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage connection combo-box selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private SelectionListener buildSchemaComboBoxSelectionListener() {
- return new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- // nothing special for "default" (double-click?)
- this.widgetSelected(event);
- }
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.selectedSchemaChanged();
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage schema combo-box selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private SelectionListener buildAddConnectionLinkSelectionListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.addConnection();
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage add connection link selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private SelectionListener buildReconnectLinkSelectionListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- DatabaseGroup.this.reconnect();
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage reconnect link selection listener"; //$NON-NLS-1$
- }
- };
- }
-
- private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile cp) {
- this.connectionChanged();
- }
- @Override // this probably won't ever get called...
- public void closed(ConnectionProfile cp) {
- this.connectionChanged();
- }
- private void connectionChanged() {
- Display.getDefault().asyncExec(
- new Runnable() {
- public void run() {
- DatabaseGroup.this.connectionChanged();
- }
- }
- );
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage connection listener"; //$NON-NLS-1$
- }
- };
- }
-
-
- // ********** listeners **********
-
- public void addListener(Listener listener) {
- if ( ! this.listeners.add(listener)) {
- throw new IllegalArgumentException("duplicate listener: " + listener); //$NON-NLS-1$
- }
- }
-
- public void removeListener(Listener listener) {
- if ( ! this.listeners.remove(listener)) {
- throw new IllegalArgumentException("missing listener: " + listener); //$NON-NLS-1$
- }
- }
-
- private Iterator<Listener> listeners() {
- return new CloneIterator<Listener>(this.listeners);
- }
-
- void fireConnectionProfileChanged(ConnectionProfile connectionProfile) {
- for (Iterator<Listener> stream = this.listeners(); stream.hasNext(); ) {
- stream.next().selectedConnectionProfileChanged(connectionProfile);
- }
- }
-
- void fireSchemaChanged(Schema schema) {
- for (Iterator<Listener> stream = this.listeners(); stream.hasNext(); ) {
- stream.next().selectedSchemaChanged(schema);
- }
- }
-
- // ********** UI components **********
-
- /**
- * build and return a label
- */
- private Label buildLabel(Composite parent, int span, String text) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- label.setLayoutData(gd);
- return label;
- }
-
- /**
- * build and return a combo-box
- */
- private Combo buildComboBox(Composite parent, int widthHint, SelectionListener listener) {
- Combo combo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- combo.addSelectionListener(listener);
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
- //data.grabExcessHorizontalSpace = true ;
- data.widthHint = widthHint;
- combo.setLayoutData(data);
- return combo;
- }
-
- /**
- * build and return a link
- */
- private Button buildButton(Composite parent, String toolTipText, Image image, SelectionListener listener) {
- Button button = new Button(parent, SWT.NONE);
- GridData data = new GridData(GridData.END, GridData.CENTER, false, false);
- data.horizontalSpan = 1;
- button.setLayoutData(data);
- button.setImage( image );
- button.setToolTipText( toolTipText);
- button.addSelectionListener(listener);
- return button;
- }
-
- // ********** listener interface **********
-
- /**
- * Allows clients to listen for changes to the selected connection profile
- * and schema.
- */
- public interface Listener extends EventListener
- {
- void selectedConnectionProfileChanged(ConnectionProfile connectionProfile);
- void selectedSchemaChanged(Schema schema);
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
deleted file mode 100644
index 842b8e78ce..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
+++ /dev/null
@@ -1,340 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaModel;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.JavaPlugin;
-import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
-import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator;
-import org.eclipse.jdt.internal.ui.wizards.TypedViewerFilter;
-import org.eclipse.jdt.ui.JavaElementComparator;
-import org.eclipse.jdt.ui.JavaElementLabelProvider;
-import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
-import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.gen.internal.ORMGenTable;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-/**
- * A wizard page allowing the entry of the default table generation
- * properties (Java classes package, base class, etc).
- * These properties apply to all tables unless explicitly overridden (in the table generation page).
- *
- * @author Danny Ju
- */
-public class DefaultTableGenerationWizardPage extends NewTypeWizardPage {
-
- private JpaProject jpaProject;
-
- /*the instance used to get/set the default properties.*/
- private ORMGenTable defaultsTable;
-
- private ORMGenCustomizer customizer;
-
- private TableGenPanel defaultTableGenPanel ;
-
- protected DefaultTableGenerationWizardPage(JpaProject jpaProject) {
- super(true, "DefaultTableGenerationWizardPage"); //$NON-NLS-1$
- this.jpaProject = jpaProject;
- setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_title);
- setDescription( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_desc);
- }
-
-
- // -------- Initialization ---------
- /**
- * The wizard owning this page is responsible for calling this method with the
- * current selection. The selection is used to initialize the fields of the wizard
- * page.
- *
- * @param selection used to initialize the fields
- */
- void init(IStructuredSelection selection) {
- IJavaElement jelem = null;
- if ( selection.getFirstElement() instanceof IJavaElement ) {
- jelem = (IJavaElement) selection.getFirstElement();
- }else{
- jelem = this.jpaProject.getJavaProject();
- }
- if( jelem !=null ){
- initContainerPage(jelem);
- initTypePage(jelem);
- }
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 4 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_CUSTOMIZE_DEFAULT_ENTITY_GENERATION);
-
- //Create entity access, collection type, etc
- defaultTableGenPanel = new TableGenPanel(composite, 4, true, this);
-
- createDomainJavaClassesPropertiesGroup(composite, 4);
- setControl(composite);
-
-
- this.setPageComplete( true );
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- ORMGenCustomizer customizer = getCustomizer();
- //If user changed the connection or schema
- if ( this.customizer != customizer ) {
- this.customizer = customizer;
- ORMGenTable newTable;
- newTable = getCustomizer().createGenTable(null);
- this.defaultsTable = newTable;
- defaultTableGenPanel.setORMGenTable(newTable);
-
- //set the super class and implemented interfaces value
- String baseClass = defaultsTable.getExtends() == null ?"" : defaultsTable.getExtends();
- setSuperClass(baseClass, true);
- setSuperInterfaces(defaultsTable.getImplements(), true);
- IPackageFragmentRoot root = getSourceFolder( defaultsTable.getSourceFolder());
- String initPackageName = this.getPackageText();
- if( initPackageName.length()==0 ){
- setPackageName( root, defaultsTable.getPackage() );
- }
- setPackageFragmentRoot(root, true/*canBeModified*/);
- }
- }
- }
-
- private IPackageFragmentRoot getSourceFolder(String srcFodler){
- IPackageFragmentRoot packageFragmentRoot=null;
- // Copied from org.eclipse.pde.internal.ui.editor.plugin.JavaAttributeWizardPage
- try {
- IJavaProject javaProject = jpaProject.getJavaProject();
-
- IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
- for (int i = 0; i < roots.length; i++) {
- if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
- //Save the default source root
- if(i==0) packageFragmentRoot = roots[i];
- //find alternative source root match the saved value
- if( roots[i].getPath().toString().equals("/"+srcFodler)){
- packageFragmentRoot=roots[i];
- break;
- }
- }
- }
- } catch (CoreException e) {
- JptUiPlugin.log(e);
- }
- return packageFragmentRoot;
- }
-
- private void setPackageName(IPackageFragmentRoot packageFragmentRoot, String packageName) {
- if( packageName == null || packageName.length() == 0 || packageFragmentRoot==null) {
- return;
- }
- //IJavaProject javaProject = jpaProject.getJavaProject();
- IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName);
- setPackageFragment(packageFragment, true/*canBeModified*/);
- }
-
-
- protected void createDomainJavaClassesPropertiesGroup(Composite composite, int columns) {
- Group parent = new Group( composite, SWT.NONE);
- parent.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_domainJavaClass);
- parent.setLayout(new GridLayout( columns, false));
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = true;
- parent.setLayoutData(layoutData);
-
- //default Java package name only available for default table generation
- createPackageControls(parent, columns);
- createContainerControls(parent, columns);
- createSuperClassControls(parent, columns);
- createSuperInterfacesControls(parent, columns);
- }
-
- @Override
- protected IStatus packageChanged() {
- IStatus status = super.packageChanged();
- IPackageFragment packageFragment = getPackageFragment();
- //String srcFolder = packageFragment.getPath().toPortableString();
- if (defaultsTable != null && !status.matches(IStatus.ERROR)) {
- defaultsTable.setPackage(packageFragment.getElementName());
- }
- return status;
- }
-
- @Override
- protected IStatus superClassChanged() {
- IStatus status = super.superClassChanged();
- String baseClass = getSuperClass();
- if (baseClass != null && defaultsTable != null && !status.matches(IStatus.ERROR)) {
- String oldBaseClass = defaultsTable.getExtends();
- if ( !baseClass.equals(oldBaseClass)) {
- defaultsTable.setExtends(baseClass);
- }
- }
- return status;
- }
- @Override
- protected IStatus containerChanged() {
- IStatus status = super.containerChanged();
- String srcFolder = getPackageFragmentRootText();
- if( !status.matches(IStatus.ERROR) ){
- if (defaultsTable != null ) {
- defaultsTable.setSourceFolder( srcFolder );
- }
- }
- return status;
- }
-
- /** Override to allow select source folder in current project only
- * @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#chooseContainer()
- */
- @Override
- protected IPackageFragmentRoot chooseContainer() {
- IJavaElement initElement= getPackageFragmentRoot();
- Class[] acceptedClasses= new Class[] { IPackageFragmentRoot.class, IJavaProject.class };
- TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, false) {
- public boolean isSelectedValid(Object element) {
- try {
- if (element instanceof IJavaProject) {
- IJavaProject jproject= (IJavaProject)element;
- IPath path= jproject.getProject().getFullPath();
- return (jproject.findPackageFragmentRoot(path) != null);
- } else if (element instanceof IPackageFragmentRoot) {
- return (((IPackageFragmentRoot)element).getKind() == IPackageFragmentRoot.K_SOURCE);
- }
- return true;
- } catch (JavaModelException e) {
- JavaPlugin.log(e.getStatus()); // just log, no UI in validation
- }
- return false;
- }
- };
-
- acceptedClasses= new Class[] { IJavaModel.class, IPackageFragmentRoot.class, IJavaProject.class };
- ViewerFilter filter= new TypedViewerFilter(acceptedClasses) {
- public boolean select(Viewer viewer, Object parent, Object element) {
- if (element instanceof IPackageFragmentRoot) {
- try {
- return (((IPackageFragmentRoot)element).getKind() == IPackageFragmentRoot.K_SOURCE);
- } catch (JavaModelException e) {
- JavaPlugin.log(e.getStatus()); // just log, no UI in validation
- return false;
- }
- }
- return super.select(viewer, parent, element);
- }
- };
-
- StandardJavaElementContentProvider provider= new StandardJavaElementContentProvider();
- ILabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
- ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), labelProvider, provider);
- dialog.setValidator(validator);
- dialog.setComparator(new JavaElementComparator());
- dialog.setTitle(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_title);
- dialog.setMessage(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_description);
- dialog.addFilter(filter);
- dialog.setInput(JavaCore.create( jpaProject.getProject()));
- dialog.setInitialSelection(initElement);
- dialog.setHelpAvailable(false);
-
- if (dialog.open() == Window.OK) {
- Object element= dialog.getFirstResult();
- if (element instanceof IJavaProject) {
- IJavaProject jproject= (IJavaProject)element;
- return jproject.getPackageFragmentRoot(jproject.getProject());
- } else if (element instanceof IPackageFragmentRoot) {
- return (IPackageFragmentRoot)element;
- }
- return null;
- }
- return null;
- }
-
- @Override
- protected void handleFieldChanged(String fieldName) {
- super.handleFieldChanged(fieldName);
- if (this.fContainerStatus.matches(IStatus.ERROR)) {
- updateStatus(fContainerStatus);
- }else if( ! this.fPackageStatus.matches(IStatus.OK) ) {
- updateStatus(fPackageStatus);
- } else if (this.fSuperClassStatus.matches(IStatus.ERROR)) {
- updateStatus(fSuperClassStatus);
- } else {
- updateStatus(Status.OK_STATUS);
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected IStatus superInterfacesChanged() {
- IStatus ret = super.superInterfacesChanged();
- if ( ret.isOK() ) {
- List interfaces = getSuperInterfaces();
- if(defaultsTable!=null)
- defaultsTable.setImplements(interfaces);
- }
- return ret;
- }
-
- private ORMGenCustomizer getCustomizer() {
- GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard();
- return wizard.getCustomizer();
- }
-
- @Override
- public final void performHelp() {
- this.getHelpSystem().displayHelp( GenerateEntitiesFromSchemaWizard.HELP_CONTEXT_ID );
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
-
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
deleted file mode 100644
index 11235033a3..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
+++ /dev/null
@@ -1,551 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceRuleFactory;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder;
-import org.eclipse.jpt.core.JpaPlatform;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.core.internal.synch.SynchronizeClassesJob;
-import org.eclipse.jpt.db.Column;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.ForeignKey;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.gen.internal.BaseEntityGenCustomizer;
-import org.eclipse.jpt.gen.internal.DatabaseAnnotationNameBuilder;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.gen.internal.PackageGenerator2;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JptUiIcons;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-
-public class GenerateEntitiesFromSchemaWizard extends Wizard
- implements INewWizard {
-
- public static final String HELP_CONTEXT_ID = JptUiPlugin.PLUGIN_ID + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
-
- private static final String DONT_SHOW_OVERWRITE_WARNING_DIALOG = "DONT_SHOW_OVERWRITE_WARNING_DIALOG";
-
- private JpaProject jpaProject;
-
- private IStructuredSelection selection;
-
- private ORMGenCustomizer customizer = null;
-
- private boolean synchronizePersistenceXml;
-
- private PromptJPAProjectWizardPage projectPage;
-
- private TablesSelectorWizardPage tablesSelectorPage;
-
- private TableAssociationsWizardPage tableAssociationsPage;
-
- private DefaultTableGenerationWizardPage defaultTableGenerationPage;
-
- private TablesAndColumnsCustomizationWizardPage tablesAndColumnsCustomizationPage;
-
- public GenerateEntitiesFromSchemaWizard() {
- this.setWindowTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_generateEntities);
- }
-
- public GenerateEntitiesFromSchemaWizard( JpaProject jpaProject, IStructuredSelection selection) {
- super();
- this.jpaProject = jpaProject;
- this.selection = selection;
- this.setWindowTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_generateEntities);
- }
-
- public Image getDefaultPageImage() {
- return JptUiPlugin.getImage( JptUiIcons.ENTITY_WIZ_BANNER ) ;
- }
-
- public void addPages() {
- super.addPages();
-
- setForcePreviousAndNextButtons(true);
-
- //If this.jpaProject is not initialized because user didn't select a JPA project
- if( this.jpaProject == null ){
- projectPage = new PromptJPAProjectWizardPage( HELP_CONTEXT_ID );
- this.addPage(projectPage);
- return;
- }
- addMainPages();
- }
-
- private void addMainPages()
- {
- this.tablesSelectorPage = new TablesSelectorWizardPage( this.jpaProject );
- this.addPage(tablesSelectorPage);
-
- this.tableAssociationsPage = new TableAssociationsWizardPage( this.jpaProject );
- this.addPage(tableAssociationsPage);
-
- this.defaultTableGenerationPage = new DefaultTableGenerationWizardPage( this.jpaProject);
- this.addPage(defaultTableGenerationPage);
- this.defaultTableGenerationPage.init(this.selection);
-
- this.tablesAndColumnsCustomizationPage = new TablesAndColumnsCustomizationWizardPage( this.jpaProject );
- this.addPage(tablesAndColumnsCustomizationPage);
- this.tablesAndColumnsCustomizationPage.init(selection);
- }
-
- public ORMGenCustomizer getORMGenCustomizer(){
- return this.customizer;
- }
-
- /**
- * Create the ORMGenCustomizer when user selects a new connection profile and schema
- *
- * JpaPlatform implementor can provide a custom ORMGenCustomizer specific to a platform
- * with AdapterFactory through Eclipse org.eclipse.core.runtime.adapters extension point:
- * <pre>
- *
- *<extension
- * point="org.eclipse.core.runtime.adapters">
- * <factory
- * adaptableType="org.eclipse.jpt.eclipselink.core.internal.EclipseLinkPlatform"
- * class="oracle.eclipse.tools.orm.internal.EclipseLinkORMGenCustomizerAdapterFactory">
- * <adapter
- * type="oracle.eclipse.tools.orm.internal.ORMGenCustomizer">
- * </adapter>
- * </factory>
- *</extension>
- *</pre>
- *
- * @param schema
- */
- public ORMGenCustomizer createORMGenCustomizer(Schema schema){
- JpaPlatform jpaPlatform = this.jpaProject.getJpaPlatform();
- Object obj = Platform.getAdapterManager().getAdapter( jpaPlatform, ORMGenCustomizer.class );
- if( obj != null && obj instanceof ORMGenCustomizer){
- customizer = (ORMGenCustomizer) obj ;
- customizer.init(getCustomizationFile(), schema );
- }else{
- customizer = new BaseEntityGenCustomizer( );
- customizer.init(getCustomizationFile(), schema );
- }
- return customizer;
- }
-
- protected String getCustomizationFileName() {
- ConnectionProfile profile = getProjectConnectionProfile();
- String connection = profile==null?"":profile.getName();
- String name = "org.eclipse.jpt.entitygen." + (connection==null?"":connection.replace(' ', '-')); //$NON-NLS-1$
- Schema schema = getDefaultSchema();
- if ( schema!= null ) {
- name += "." + schema.getName();//$NON-NLS-1$
- }
- return name.toLowerCase();
- }
-
- /**
- * Returns the nodes state file.
- */
- private File getCustomizationFile() {
- String projectPath = jpaProject.getProject().getLocation().toPortableString();
- File genDir = new File(projectPath + "/.settings");//$NON-NLS-1$
- genDir.mkdirs();
- return new File(genDir, getCustomizationFileName());
- }
-
- public boolean performFinish() {
- if( this.jpaProject == null )
- return true;
-
- try {
- this.customizer.setDatabaseAnnotationNameBuilder( buildDatabaseAnnotationNameBuilder() );
- this.customizer.save();
- } catch (IOException e) {
- JptUiPlugin.log(e);
- }
-
- this.synchronizePersistenceXml = this.tablesSelectorPage.synchronizePersistenceXml();
-
- if(shouldShowOverwriteWarning())
- PackageGenerator2.setOverwriteConfirmer( new OverwriteConfirmer());
-
- WorkspaceJob genEntitiesJob = new GenerateEntitiesJob( this.jpaProject, getCustomizer() );
-
- WorkspaceJob synchClassesJob = null;
- if (synchronizePersistenceXml()) {
- // we currently only support *one* persistence.xml file per project
- PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
- if (persistenceXml != null) {
- // TODO casting to IFile - just trying to get rid of all compiler errors for now
- synchClassesJob = new SynchronizeClassesJob((IFile) persistenceXml.getResource());
- }
- }
-
- genEntitiesJob.schedule();
- if (synchClassesJob != null) {
- synchClassesJob.schedule();
- }
-
- return true;
- }
-
- // ********** generate entities job **********
-
- static class GenerateEntitiesJob extends WorkspaceJob {
- JpaProject jpaProject ;
- ORMGenCustomizer customizer;
- GenerateEntitiesJob(JpaProject jpaProject, ORMGenCustomizer customizer) {
- super(JptUiMessages.EntitiesGenerator_jobName);
- this.customizer = customizer;
- this.jpaProject = jpaProject ;
- IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
- this.setRule(ruleFactory.modifyRule(jpaProject.getProject()));
- }
-
- @Override
- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- try{
- PackageGenerator2.generate(jpaProject.getJavaProject(),this.customizer, monitor);
- }catch(OperationCanceledException e){
- //user canceled generation
- }
- return Status.OK_STATUS;
- }
-
- }
- public static boolean shouldShowOverwriteWarning(){
- IEclipsePreferences pref = new InstanceScope().getNode( JptUiPlugin.PLUGIN_ID);
- boolean ret = ! pref.getBoolean( DONT_SHOW_OVERWRITE_WARNING_DIALOG, false) ;
- return( ret );
- }
-
- // ********** overwrite confirmer **********
-
- static class OverwriteConfirmer implements org.eclipse.jpt.gen.internal.OverwriteConfirmer {
- private boolean overwriteAll = false;
- private boolean skipAll = false;
-
- OverwriteConfirmer() {
- }
-
- public boolean overwrite(final String className) {
- if (this.overwriteAll) {
- return true;
- }
- if (this.skipAll) {
- return false;
- }
- return this.promptUser(className);
- }
-
- private boolean promptUser(final String className) {
- // get on the UI thread synchronously, need feedback before continuing
- final boolean ret[]=new boolean[1];
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- final OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(Display.getCurrent().getActiveShell(), className);
- dialog.open();
- if (dialog.getReturnCode() == Window.CANCEL) {
- //throw new OperationCanceledException();
- skipAll = true;
- ret[0] = false;
- return;
- }
- if (dialog.yes()) {
- ret[0] = true;
- }
- if (dialog.yesToAll()) {
- overwriteAll = true;
- ret[0] = true;
- }
- if (dialog.no()) {
- ret[0] = false;
- }
- if (dialog.noToAll()) {
- skipAll = true;
- ret[0] = false;
- }
- }
- });
- return ret[0];
- }
-
- }
-
-
- // ********** overwrite dialog **********
-
- static class OverwriteConfirmerDialog extends Dialog {
- private final String className;
- private boolean yes = false;
- private boolean yesToAll = false;
- private boolean no = false;
- private boolean noToAll = false;
-
- OverwriteConfirmerDialog(Shell parent, String className) {
- super(parent);
- this.className = className;
- }
-
- @Override
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText(JptUiMessages.OverwriteConfirmerDialog_title);
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
- GridLayout gridLayout = (GridLayout) composite.getLayout();
- gridLayout.numColumns = 1;
-
- Label text = new Label(composite, SWT.LEFT);
- text.setText(NLS.bind(JptUiMessages.OverwriteConfirmerDialog_text, this.className));
- text.setLayoutData(new GridData());
-
- createDontShowControl(composite);
-
- return composite;
- }
-
- protected Control createDontShowControl(Composite composite) {
- final Button checkbox = new Button( composite, SWT.CHECK );
- checkbox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_doNotShowWarning );
- checkbox.setSelection(false);
- final IEclipsePreferences pref = new InstanceScope().getNode( JptUiPlugin.PLUGIN_ID);
- checkbox.setLayoutData( new GridData(GridData.FILL_BOTH) );
- checkbox.addSelectionListener(new SelectionListener (){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- boolean b = checkbox.getSelection();
- pref.putBoolean( DONT_SHOW_OVERWRITE_WARNING_DIALOG, b);
- }
- });
- return checkbox;
- }
-
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- this.createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
- this.createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false);
- this.createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
- this.createButton(parent, IDialogConstants.NO_TO_ALL_ID, IDialogConstants.NO_TO_ALL_LABEL, false);
- this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
- }
-
- @Override
- protected void buttonPressed(int buttonId) {
- switch (buttonId) {
- case IDialogConstants.YES_ID :
- this.yesPressed();
- break;
- case IDialogConstants.YES_TO_ALL_ID :
- this.yesToAllPressed();
- break;
- case IDialogConstants.NO_ID :
- this.noPressed();
- break;
- case IDialogConstants.NO_TO_ALL_ID :
- this.noToAllPressed();
- break;
- case IDialogConstants.CANCEL_ID :
- this.cancelPressed();
- break;
- default :
- break;
- }
- }
-
- private void yesPressed() {
- this.yes = true;
- this.setReturnCode(OK);
- this.close();
- }
-
- private void yesToAllPressed() {
- this.yesToAll = true;
- this.setReturnCode(OK);
- this.close();
- }
-
- private void noPressed() {
- this.no = true;
- this.setReturnCode(OK);
- this.close();
- }
-
- private void noToAllPressed() {
- this.noToAll = true;
- this.setReturnCode(OK);
- this.close();
- }
-
- boolean yes() {
- return this.yes;
- }
-
- boolean yesToAll() {
- return this.yesToAll;
- }
-
- boolean no() {
- return this.no;
- }
-
- boolean noToAll() {
- return this.noToAll;
- }
- }
-
-
- private DatabaseAnnotationNameBuilder buildDatabaseAnnotationNameBuilder() {
- return new LocalDatabaseAnnotationNameBuilder(this.jpaProject.getJpaPlatform().getEntityGeneratorDatabaseAnnotationNameBuilder());
- }
-
- // ********** name builder adapter **********
-
- /**
- * adapt the JPA platform-supplied builder to the builder interface
- * expected by the entity generator
- */
- static class LocalDatabaseAnnotationNameBuilder implements DatabaseAnnotationNameBuilder {
- private EntityGeneratorDatabaseAnnotationNameBuilder builder;
- LocalDatabaseAnnotationNameBuilder(EntityGeneratorDatabaseAnnotationNameBuilder builder) {
- super();
- this.builder = builder;
- }
- public String buildTableAnnotationName(String entityName, Table table) {
- return this.builder.buildTableAnnotationName(entityName, table);
- }
- public String buildColumnAnnotationName(String attributeName, Column column) {
- return this.builder.buildColumnAnnotationName(attributeName, column);
- }
- public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) {
- return this.builder.buildJoinColumnAnnotationName(attributeName, foreignKey);
- }
- public String buildJoinColumnAnnotationName(Column column) {
- return this.builder.buildJoinColumnAnnotationName(column);
- }
- public String buildJoinTableAnnotationName(Table table) {
- return this.builder.buildJoinTableAnnotationName(table);
- }
- }
-
- @Override
- public IWizardPage getStartingPage() {
- if (this.projectPage != null) {
- if (this.tablesSelectorPage != null)
- return this.tablesSelectorPage;
- else
- return this.projectPage;
- }
- else
- return super.getStartingPage();
- }
-
- public ORMGenCustomizer getCustomizer (){
- return customizer;
- }
-// Collection<Table> getPossibleTables() {
-// if ( this.tablesSelectorPage != null) {
-// return this.tablesSelectorPage.getTables();
-// }
-// return ( this.projectDefaultSchemaExists()) ? CollectionTools.collection( this.getDefaultSchema().tables()) : Collections.<Table>emptyList();
-// }
-
- public ConnectionProfile getProjectConnectionProfile() {
- return this.jpaProject.getConnectionProfile();
- }
-
- public JpaProject getJpaProject(){
- return this.jpaProject;
- }
-
- public void setJpaProject(JpaProject jpaProject) {
- if (this.jpaProject == null) {
- this.jpaProject = jpaProject;
- IWizardPage currentPage = getContainer().getCurrentPage();
- if (projectPage != null && currentPage.equals(projectPage)) {
- addMainPages();
- }
- }
- }
-
- public Schema getDefaultSchema() {
- return getJpaProject().getDefaultDbSchema() ;
- }
-
- public boolean synchronizePersistenceXml() {
- return this.synchronizePersistenceXml;
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
-
- Object sel = selection.getFirstElement();
- if( sel instanceof IResource ){
- IProject proj = ((IResource) sel).getProject();
- JpaProject jpaProj = JptCorePlugin.getJpaProject( proj );
- this.jpaProject = jpaProj;
- }else if( sel instanceof org.eclipse.jdt.core.IPackageFragmentRoot ){
- org.eclipse.jdt.core.IPackageFragmentRoot root = (org.eclipse.jdt.core.IPackageFragmentRoot)sel;
- IProject proj = root.getJavaProject().getProject();
- JpaProject jpaProj = JptCorePlugin.getJpaProject( proj );
- this.jpaProject = jpaProj;
- }else if( sel instanceof org.eclipse.jdt.core.IPackageFragment){
- org.eclipse.jdt.core.IPackageFragment frag = (org.eclipse.jdt.core.IPackageFragment)sel;
- IProject proj = frag.getJavaProject().getProject();
- JpaProject jpaProj = JptCorePlugin.getJpaProject( proj );
- this.jpaProject = jpaProj;
- }
-
- this.selection = selection;
- this.setWindowTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_generateEntities);
-
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JoinColumnsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JoinColumnsPage.java
deleted file mode 100644
index 06eccf9cae..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JoinColumnsPage.java
+++ /dev/null
@@ -1,626 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeMap;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.dialogs.IPageChangedListener;
-import org.eclipse.jface.dialogs.PageChangedEvent;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.ICellModifier;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jpt.db.Column;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.ui.internal.util.TableLayoutComposite;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-
-
-public class JoinColumnsPage extends NewAssociationWizardPage {
-
- private Label joinColumnsDescLabel1;
- /*the table containing the association columns between table1 and table2
- * , or table1 and join table if many to many*/
- private TableViewer joinColumnsTable1;
- private ArrayList<SimpleJoin> tableDataModel1 = new ArrayList<SimpleJoin>();
- private Composite tablesGroup1;
-
- private Label joinColumnsDescLabel2;
- /*the table containing the association columns between join table and table2
- * if many to many*/
- private TableViewer joinColumnsTable2;
- private ArrayList<SimpleJoin> tableDataModel2 = new ArrayList<SimpleJoin>();
- private Composite tablesGroup2;
-
- static final String[] JOINCOLUMNS_TABLE_COLUMN_PROPERTIES = { "referrerColumn", "referencedColumn" };
-
- private static final int JOINCOLUMN1_COLUMN_INDEX = 0;
- private static final int JOINCOLUMN2_COLUMN_INDEX = 1;
-
- protected JoinColumnsPage(ORMGenCustomizer customizer ) {
- super(customizer, "JoinColumnsPage");
- setTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_title);
- setDescription(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_desc);
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_JOIN_COLUMNS);
-
- tablesGroup1 = new Composite(composite, SWT.SHADOW_ETCHED_IN);
- tablesGroup1.setLayoutData(new GridData());
- tablesGroup1.setLayout(new GridLayout(2, false));
- createJoinColumnsTableControl1(tablesGroup1);
-
- //createMtmJoinColumnsTable2(composite);
-
- setControl(composite);
- this.setPageComplete( false);
-
- ((WizardDialog)getContainer()).addPageChangedListener(new IPageChangedListener(){
- public void pageChanged(PageChangedEvent event) {
- if( event.getSelectedPage() == JoinColumnsPage.this ){
- ((Composite)JoinColumnsPage.this.getControl()).getParent().layout() ;
-
- }
- }
- });
- }
-
- private void createMtmJoinColumnsTable2(Composite composite) {
- tablesGroup2 = new Composite(composite, SWT.SHADOW_ETCHED_IN);
- tablesGroup2.setLayoutData(new GridData());
- tablesGroup2.setLayout(new GridLayout(2, false));
- createJoinColumnsTableControl2(tablesGroup2);
- }
-
- /**
- * Update wizard page UI with new table names
- */
- public void updateWithNewTables() {
- String cardinality = this.getCardinality() ;
- if( Association.MANY_TO_MANY.equals( cardinality ) ){
- updateWithMtmTables();
- }else{
- updateWithOtmTables();
- }
- }
-
- /**
- * Update Wizard UI with a single TableViewer with columns from the two associated database tables
- */
- public void updateWithOtmTables() {
- TableColumn[] columns = joinColumnsTable1.getTable().getColumns();
- String table1Name = this.getReferrerTableName() ;
- String table2Name = this.getReferencedTableName() ;
-
- if( table1Name ==null || table2Name == null )
- return;
-
- columns[0].setText( table1Name );
- columns[1].setText( table2Name );
-
- //Hide the Join column table 2
- if( tablesGroup2 !=null )
- tablesGroup2.setVisible(false);
-
- tableDataModel1.clear();
- joinColumnsTable1.refresh();
-
- String msg = String.format(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_label, table1Name, table2Name);
- joinColumnsDescLabel1.setText(msg);
- joinColumnsDescLabel1.setToolTipText( msg );
- tablesGroup1.layout();
-
- String[] referrerColumnValues = getTableColumns(table1Name);
- String[] referencedColumnValues = getTableColumns(table2Name);
-
- updateCellEditors(joinColumnsTable1, referrerColumnValues, referencedColumnValues);
-
-
- ((Composite)this.getControl()).layout() ;
- }
-
- /**
- * Update Wizard UI with a two TableViewers with the first with columns from table1 to the MTM join table
- * and the second one with columns from the MTM join table to table2
- */
- public void updateWithMtmTables() {
- TableColumn[] columns = joinColumnsTable1.getTable().getColumns();
- String table1Name = this.getReferrerTableName() ;
- String table2Name = this.getReferencedTableName() ;
- String joinTableName = this.getJoinTableName() ;
- if( table1Name==null || table2Name==null || joinTableName==null ){
- return;
- }
- if( tablesGroup2 == null ){
- createMtmJoinColumnsTable2( tablesGroup1.getParent());
- }
-
- columns[0].setText( table1Name==null?"":table1Name );
- columns[1].setText( table2Name==null?"":joinTableName );
-
- //Update join column TableViewer 1
- tableDataModel1.clear();
- joinColumnsTable1.refresh();
-
- String msg = String.format(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_label, table1Name, joinTableName);
- joinColumnsDescLabel1.setText(msg);
- joinColumnsDescLabel1.setToolTipText( msg );
- String[] referrerColumnValues = getTableColumns(table1Name);
- String[] referencedColumnValues = getTableColumns(joinTableName);
-
- updateCellEditors(joinColumnsTable1, referrerColumnValues, referencedColumnValues );
-
- //Update join column TableViewer 2
- columns = joinColumnsTable2.getTable().getColumns();
- columns[0].setText( joinTableName==null?"":joinTableName );
- columns[1].setText( table2Name==null?"":table2Name );
- tablesGroup1.layout();
-
- tableDataModel2.clear();
- joinColumnsTable2.refresh();
- msg = String.format(JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_label, joinTableName, table2Name);
- joinColumnsDescLabel2.setText(msg);
- joinColumnsDescLabel2.setToolTipText( msg );
- referrerColumnValues = getTableColumns(joinTableName);
- referencedColumnValues = getTableColumns(table2Name);
- updateCellEditors(joinColumnsTable2, referrerColumnValues, referencedColumnValues );
-
- tablesGroup2.layout();
-
- //Show the Join column TableViewer 2
- tablesGroup2.setVisible(true);
-
-
- ((Composite)this.getControl()).layout(new Control[]{this.tablesGroup1, this.tablesGroup2});
- }
-
-
- private void createAddRemoveButtonComposite(Composite tablesGroup, final TableViewer joinColumnsTable, final ArrayList<SimpleJoin> tableDataModel) {
- //Add and Remove JoinColumns buttons
- Composite buttonComposite = new Composite(tablesGroup, SWT.NULL);
- GridLayout buttonLayout = new GridLayout(1, false);
- buttonComposite.setLayout(buttonLayout);
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- buttonComposite.setLayoutData(data);
-
- Button addButton = new Button(buttonComposite, SWT.PUSH);
- addButton.setText( JptUiEntityGenMessages.add );
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- addButton.setLayoutData(gridData);
- addButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- @SuppressWarnings("unchecked")
- public void widgetSelected(SelectionEvent e) {
-
- SimpleJoin join = getDefaultNewJoin(joinColumnsTable);
- tableDataModel.add(join);
- joinColumnsTable.refresh();
-
- //Update Wizard model
- TreeMap<String, String> joins = null;
- if( joinColumnsTable == joinColumnsTable1 ){
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1 );
- }else{
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2 );
- }
- joins.put( join.foreignKey, join.primaryKey);
-
- updatePageComplete();
- }
- });
-
- Button removeButton = new Button(buttonComposite, SWT.PUSH);
- removeButton.setText( JptUiEntityGenMessages.remove );
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- removeButton.setLayoutData(gridData);
- removeButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- @SuppressWarnings("unchecked")
- public void widgetSelected(SelectionEvent e) {
- StructuredSelection selection = (StructuredSelection)joinColumnsTable.getSelection();
- if( selection.isEmpty())
- return;
- SimpleJoin join = (SimpleJoin)selection.getFirstElement();
-
- //Update TableViewer model
- tableDataModel.remove( join );
- //Update Wizard model
-
- TreeMap<String, String> joins = null;
- if( joinColumnsTable == joinColumnsTable1 ){
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1 );
- }else{
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2 );
- }
- joins.remove(join.foreignKey);
-
- joinColumnsTable.refresh();
- }
- });
-
- addButton.setFocus();
-
- }
-
- protected SimpleJoin getDefaultNewJoin(TableViewer joinColumnsTable) {
- String table1Name = "";
- String table2Name = "";
-
- TreeMap<String, String> existingJoins = null;
- if( joinColumnsTable == this.joinColumnsTable1 ){
- existingJoins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1 );
- if( this.getJoinTableName() == null) {
- table1Name = this.getReferrerTableName();
- table2Name = this.getReferencedTableName() ;
- }else{
- table1Name = this.getReferrerTableName();
- table2Name = this.getJoinTableName() ;
- }
- }else{
- existingJoins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2 );
- table1Name = this.getJoinTableName();
- table2Name = this.getReferencedTableName() ;
- }
- //find next available column
- String[] table1ColumnValues = getTableColumns(table1Name);
- String nextCol1 = "";
- for( String s: table1ColumnValues ){
- if( !existingJoins.keySet().contains(s)){
- nextCol1 = s;
- break;
- }
- }
-
- String[] table2ColumnValues = getTableColumns(table2Name);
- String nextCol2 = "";
- for( String s: table2ColumnValues ){
- if( !existingJoins.values().contains(s)){
- nextCol2 = s;
- break;
- }
- }
- return new SimpleJoin( nextCol1, nextCol2);
- }
-
- public boolean canFlipToNextPage() {
- return isPageComplete();
- }
-
- public void updatePageComplete() {
- boolean ret = tableDataModel1.size()> 0 ;
- setPageComplete( ret );
- }
-
- private Label createLabel(Composite container, int span, String text) {
- Label label = new Label(container, SWT.NONE);
- label.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- label.setLayoutData(gd);
- return label;
- }
-
- private void createJoinColumnsTableControl1(Composite tablesGroup) {
- joinColumnsDescLabel1 = createLabel(tablesGroup, 2, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_label );
- joinColumnsTable1 = createJoinColumnsTableControl(tablesGroup, this.tableDataModel1);
- createAddRemoveButtonComposite(tablesGroup, joinColumnsTable1, tableDataModel1);
- }
-
- private void createJoinColumnsTableControl2(Composite tablesGroup) {
- joinColumnsDescLabel2 = createLabel(tablesGroup, 2, JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_colsPage_label );
- joinColumnsTable2 = createJoinColumnsTableControl(tablesGroup, this.tableDataModel2);
- createAddRemoveButtonComposite(tablesGroup, joinColumnsTable2, tableDataModel2);
- }
-
- private TableViewer createJoinColumnsTableControl(Composite parent, ArrayList<SimpleJoin> tableDataModel ){
-
- TableLayoutComposite layout= new TableLayoutComposite(parent, SWT.NONE);
- addColumnLayoutData(layout);
-
- final org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(layout, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER );
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- TableColumn referrerColumn = new TableColumn(table, SWT.NONE, JOINCOLUMN1_COLUMN_INDEX);
- referrerColumn.setText("%table1");
- referrerColumn.setResizable(true);
-
- TableColumn referencedColumn = new TableColumn(table, SWT.NONE, JOINCOLUMN2_COLUMN_INDEX);
- referencedColumn.setText("%table2");
- referencedColumn.setResizable(true);
-
- GridData gd= new GridData(GridData.FILL_BOTH);
- gd.heightHint= SWTUtil.getTableHeightHint(table, 3);
- gd.widthHint = 300;
- layout.setLayoutData(gd);
-
- TableViewer newJoinColumnsTable = new TableViewer(table);
- newJoinColumnsTable.setUseHashlookup(true);
- newJoinColumnsTable.setLabelProvider(this.buildTableTableLabelProvider());
- newJoinColumnsTable.setContentProvider(this.buildTableTableContentProvider());
- newJoinColumnsTable.setSorter(new ViewerSorter() {
- public int compare(Viewer viewer, Object e1, Object e2) {
- return ((SimpleJoin) e1).foreignKey.compareTo(((SimpleJoin) e2).foreignKey);
- }
- });
-
- newJoinColumnsTable.addPostSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- //handleTablesListSelectionChanged(event);
- }
- });
- populateTableDataModel();
- newJoinColumnsTable.setInput( tableDataModel );
- return newJoinColumnsTable;
- }
-
- @SuppressWarnings("unchecked")
- public void populateTableDataModel(){
- HashMap<String, Object> dataModel = (HashMap<String, Object> )getWizardDataModel();
- TreeMap<String, String> joinColumns = (TreeMap<String, String>)dataModel.get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1);
- if( joinColumns!= null ){
- for( String referrerColumn : joinColumns.keySet() ){
- tableDataModel1.add(new SimpleJoin(referrerColumn, joinColumns.get(referrerColumn) ));
- }
- }
-
- TreeMap<String, String> joinColumns2 = (TreeMap<String, String>)dataModel.get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2);
- if( joinColumns2!= null ){
- for( String referrerColumn : joinColumns2.keySet() ){
- tableDataModel2.add(new SimpleJoin(referrerColumn, joinColumns2.get(referrerColumn) ));
- }
- }
-
- }
-
- private IContentProvider buildTableTableContentProvider() {
- return new JoinColumnsContentProvider();
- }
-
-
- private IBaseLabelProvider buildTableTableLabelProvider() {
- return new JoinColumnsTableLabelProvider();
- }
-
-
- private void addColumnLayoutData(TableLayoutComposite layout) {
- layout.addColumnData(new ColumnWeightData(50, true));
- layout.addColumnData(new ColumnWeightData(50, true));
- }
-
-
- private void updateCellEditors(TableViewer joinColumnsTable, String[] referrerColumnValues, String[] referencedColumnValues ){
- joinColumnsTable.setColumnProperties(JOINCOLUMNS_TABLE_COLUMN_PROPERTIES);
- ComboBoxCellEditor[] editors = new ComboBoxCellEditor[JOINCOLUMNS_TABLE_COLUMN_PROPERTIES.length];
-
- editors[JOINCOLUMN1_COLUMN_INDEX]= new ComboBoxCellEditor(joinColumnsTable.getTable(), referrerColumnValues, SWT.SINGLE);
- editors[JOINCOLUMN2_COLUMN_INDEX]= new ComboBoxCellEditor(joinColumnsTable.getTable(), referencedColumnValues, SWT.SINGLE);
-
- joinColumnsTable.setCellEditors(editors);
- joinColumnsTable.setCellModifier(this.buildTableTableCellModifier(joinColumnsTable, referrerColumnValues, referencedColumnValues ));
- }
-
- public String[] getTableColumns(String tableName){
- Schema schema = (Schema)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_SCHEMA);
- Table table = schema.getTableNamed(tableName);
- Iterator<Column> columns = table.columns() ;
- List<String> list = new ArrayList<String>();
- while( columns.hasNext() ){
- list.add(columns.next().getName());
- }
- String[] ret = new String[list.size()];
- list.toArray(ret);
- return ret;
- }
-
- private ICellModifier buildTableTableCellModifier(TableViewer joinColumnsTable, String[] referrerColumnValues, String[] referencedColumnValues) {
- return new JoinColumnsCellModifier(joinColumnsTable, referrerColumnValues, referencedColumnValues);
- }
-
- /**
- * A ContentProvider translates the SimpleJoin list into a Collection for display
- *
- */
- private class JoinColumnsContentProvider implements IStructuredContentProvider {
-
- JoinColumnsContentProvider() {
- super();
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
- public void dispose() {}
- public Object[] getElements(Object inputElement) {
- return ((Collection<?>) inputElement).toArray();
- }
- }
-
- /**
- * Simple value object used as model backing the JFace table
- *
- */
- private class SimpleJoin {
- public SimpleJoin(String foreignKey, String primaryKey) {
- this.foreignKey = foreignKey;
- this.primaryKey = primaryKey;
- }
- public String foreignKey;
- public String primaryKey;
-
- public String toString(){
- return "["+ this.foreignKey + " = " + this.primaryKey + "]";
- }
- }
-
- /**
- * A CellModifier to update the join columns in the wizard data model
- */
- private class JoinColumnsCellModifier implements ICellModifier {
- private TableViewer joinColumnsTable;
- private String[] referrerColumnValues;
- private String[] referencedColumnValues;
- JoinColumnsCellModifier(TableViewer joinColumnsTable, String[] referrerColumnValues, String[] referencedColumnValues) {
- super();
- this.joinColumnsTable = joinColumnsTable;
- this.referrerColumnValues = referrerColumnValues;
- this.referencedColumnValues = referencedColumnValues;
- }
-
- public boolean canModify(Object element, String property) {
- return true;
- }
-
- @SuppressWarnings("unchecked")
- public Object getValue(Object element, String property) {
-// SimpleJoin join = (SimpleJoin) element;
-// if (property.equals(JOINCOLUMNS_TABLE_COLUMN_PROPERTIES[JOINCOLUMN2_COLUMN_INDEX])) {
-// return join.primaryKey;
-// }
-// return join.foreignKey;
- // returnt the index of the value in the ComboxCellEditor
- ArrayList<SimpleJoin> tableDataModel = (ArrayList<SimpleJoin>) joinColumnsTable.getInput();
- for(int i=0; i< tableDataModel.size(); i ++ ){
- if( tableDataModel.get(i) == element )
- return new Integer(i);
- }
- return new Integer(0);
-
- }
-
- /**
- * element is the selected TableItem
- * value is the selected item index in the comboCellEditor
- */
- @SuppressWarnings("unchecked")
- public void modify(Object element, String property, Object value) {
- if ( ! (element instanceof TableItem)) {
- return;
- }
- Integer index = (Integer)value;
- TableItem item = (TableItem)element;
- boolean unchanged = false;
- SimpleJoin join = (SimpleJoin) item.getData();
- if (property.equals(JOINCOLUMNS_TABLE_COLUMN_PROPERTIES[JOINCOLUMN1_COLUMN_INDEX])) {
- unchanged = join.foreignKey.equals( referrerColumnValues[ index.intValue() ] );
- if (! unchanged) {
-
- //update the wizard datamodel
- TreeMap<String, String> joins = null;
- if( joinColumnsTable == joinColumnsTable1 ){
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1 );
- }else{
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2 );
- }
- joins.remove(join.foreignKey);
- joins.put(referrerColumnValues[ index.intValue() ], join.primaryKey);
-
- //Update the TableViewer model
- join.foreignKey = referrerColumnValues[ index.intValue()];
- joinColumnsTable.refresh();
- }
- return;
- }
-
- if (property.equals(JOINCOLUMNS_TABLE_COLUMN_PROPERTIES[JOINCOLUMN2_COLUMN_INDEX])) {
- unchanged = join.primaryKey.equals( referencedColumnValues[ index.intValue()] ) ;
- if (! unchanged) {
- //Update the TableViewer model
- join.primaryKey = referencedColumnValues[ index.intValue()] ;
-
- //Update wizard data model
- TreeMap<String, String> joins = null;
- if( joinColumnsTable == joinColumnsTable1 ){
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1 );
- }else{
- joins = (TreeMap<String, String>)getWizardDataModel().get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2 );
- }
- joins.put(join.foreignKey, join.primaryKey);
-
- joinColumnsTable.refresh();
- }
- }
-
-
- }
-
- }
-
- /**
- * A table label provider to return the join column names for display
- *
- */
- private final class JoinColumnsTableLabelProvider extends LabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
- public String getColumnText(Object element, int columnIndex) {
- if( !(element instanceof SimpleJoin) )
- return null;
- switch (columnIndex) {
- case 0:
- return ((SimpleJoin)element).foreignKey;
- case 1:
- return ((SimpleJoin)element).primaryKey;
- default:
- Assert.isTrue(false);
- return null;
- }
- }
- public String getText(Object element) {
- return getColumnText(element, 0); // needed to make the sorter work
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JptUiEntityGenMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JptUiEntityGenMessages.java
deleted file mode 100644
index b5c1c33350..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/JptUiEntityGenMessages.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Localized messages used by Dali UI.
- *
- * @version 2.0
- * @since 2.0
- */
-public class JptUiEntityGenMessages {
- private static final String BUNDLE_NAME = "jpt_ui_entity_gen"; //$NON-NLS-1$
- private static final Class<?> BUNDLE_CLASS = JptUiEntityGenMessages.class;
-
- public static String GenerateEntitiesWizard_tableSelectPage_Restore_Defaults;
- public static String GenerateEntitiesWizard_generateEntities;
- public static String GenerateEntitiesWizard_doNotShowWarning;
- public static String GenerateEntitiesWizard_selectJPAProject;
- public static String GenerateEntitiesWizard_selectJPAProject_msg;
- public static String GenerateEntitiesWizard_tableSelectPage_selectTable;
- public static String GenerateEntitiesWizard_tableSelectPage_chooseEntityTable;
- public static String GenerateEntitiesWizard_tableSelectPage_synchronizeClasses;
- public static String GenerateEntitiesWizard_tableSelectPage_tables;
- public static String GenerateEntitiesWizard_tableSelectPage_tableColumn;
- //Database connection group
- public static String connection;
- public static String addConnectionLink;
- public static String connectLink;
- public static String schemaInfo;
- public static String schema;
- public static String connectingToDatabase;
-
- //Default table gen properties
- public static String GenerateEntitiesWizard_defaultTablePage_title;
- public static String GenerateEntitiesWizard_defaultTablePage_desc;
- public static String GenerateEntitiesWizard_defaultTablePage_domainJavaClass;
- public static String GenerateEntitiesWizard_defaultTablePage_tableMapping;
- public static String GenerateEntitiesWizard_tablePanel_className;
- public static String GenerateEntitiesWizard_defaultTablePage_fetch;
- public static String GenerateEntitiesWizard_defaultTablePage_collType;
- public static String GenerateEntitiesWizard_defaultTablePage_sequence;
- public static String GenerateEntitiesWizard_defaultTablePage_sequenceNote;
- public static String GenerateEntitiesWizard_defaultTablePage_access;
- public static String GenerateEntitiesWizard_defaultTablePage_keyGen;
- public static String GenerateEntitiesWizard_defaultTablePage_genOptionalAnnotations;
- public static String GenerateEntitiesWizard_defaultTablePage_genOptionalAnnotations_desc;
-
- //Asso figure
- public static String manyToOneDesc;
- public static String oneToOneDesc;
- public static String manyToManyDesc;
- //table association wizard page
- public static String GenerateEntitiesWizard_assocPage_title;
- public static String GenerateEntitiesWizard_assocPage_desc;
- public static String GenerateEntitiesWizard_assocPage_label;
- public static String GenerateEntitiesWizard_assocPage_newAssoc;
- public static String GenerateEntitiesWizard_assocPage_delAssoc;
- public static String GenerateEntitiesWizard_assocEditor_genAssoc;
- public static String GenerateEntitiesWizard_assocEditor_entityRef;
- public static String property;
- public static String cascade;
- public static String GenerateEntitiesWizard_assocEditor_setRef;
- public static String GenerateEntitiesWizard_assocEditor_joinedWhen;
- public static String GenerateEntitiesWizard_assocEditor_tableJoin;
- public static String cardinality;
- public static String selectCascadeDlgTitle;
- //new association wizard
- public static String GenerateEntitiesWizard_newAssoc_title;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_title;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_desc;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_assocKind;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_simpleAssoc;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_m2mAssoc;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_assocTables;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_table1;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_table2;
- public static String GenerateEntitiesWizard_newAssoc_tablesPage_intermediateTable;
- public static String GenerateEntitiesWizard_newAssoc_colsPage_title;
- public static String GenerateEntitiesWizard_newAssoc_colsPage_desc;
- public static String GenerateEntitiesWizard_newAssoc_colsPage_label;
- public static String add;
- public static String remove;
- public static String GenerateEntitiesWizard_newAssoc_cardinalityPage_title;
- public static String GenerateEntitiesWizard_newAssoc_cardinalityPage_desc;
- public static String manyToOne;
- public static String oneToMany;
- public static String oneToOne;
- public static String manyToMany;
- //select table dialog
- public static String selectTableDlgTitle;
- public static String selectTableDlgDesc;
- //individual table and column gen properties
- public static String GenerateEntitiesWizard_tablesAndColumnsPage_title;
- public static String GenerateEntitiesWizard_tablesAndColumnsPage_desc;
- public static String GenerateEntitiesWizard_tablesAndColumnsPage_labelTableAndColumns;
- public static String GenerateEntitiesWizard_colPanel_genProp;
- public static String GenerateEntitiesWizard_colPanel_colMapping;
- public static String GenerateEntitiesWizard_colPanel_propName;
- public static String GenerateEntitiesWizard_colPanel_propType;
- public static String GenerateEntitiesWizard_colPanel_mapKind;
- public static String GenerateEntitiesWizard_colPanel_colUpdateable;
- public static String GenerateEntitiesWizard_colPanel_colInsertable;
- public static String GenerateEntitiesWizard_colPanel_beanProp;
- public static String GenerateEntitiesWizard_colPanel_getterScope;
- public static String GenerateEntitiesWizard_colPanel_setterScope;
- static {
- NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS);
- }
-
- private JptUiEntityGenMessages() {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizard.java
deleted file mode 100644
index e70a88d5d1..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizard.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.TreeMap;
-
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-
-
-public class NewAssociationWizard extends Wizard {
-
- public static String ASSOCIATION_SCHEMA = "ASSOCIATION_SCHEMA";
- public static String ASSOCIATION_REFERRER_TABLE = "ASSOCIATION_REFERRER_TABLE";
- public static String ASSOCIATION_REFERENCED_TABLE = "ASSOCIATION_REFERENCED_TABLE";
- public static String ASSOCIATION_JOIN_COLUMNS1 = "ASSOCIATION_REFERRER_COLUMNS1";
- public static String ASSOCIATION_JOIN_COLUMNS2 = "ASSOCIATION_REFERRER_COLUMNS2"; //used in MTM associations only
- public static String ASSOCIATION_JOIN_TABLE = "ASSOCIATION_JOIN_TABLE"; // TreeMap<String, String>
- public static String ASSOCIATION_CADINALITY = "ASSOCIATION_CADINALITY";
-
- private JpaProject jpaProject;
- private HashMap<String, Object> associationDataModel = new HashMap<String, Object>();
-
- private ORMGenCustomizer customizer = null;
-
- private AssociationTablesPage associationTablesPage;
- private JoinColumnsPage joinColumnsPage;
- private CardinalityPage cardinalityPage;
-
- public NewAssociationWizard( JpaProject jpaProject, ORMGenCustomizer customizer ) {
- super();
- this.jpaProject = jpaProject;
- this.customizer = customizer;
- this.setWindowTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_newAssoc_title);
-
- this.associationDataModel.put( NewAssociationWizard.ASSOCIATION_SCHEMA, this.customizer.getSchema());
- this.associationDataModel.put( NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1, new TreeMap<String, String>());
- this.associationDataModel.put( NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2, new TreeMap<String, String>());
- }
-
- public void addPages() {
- super.addPages();
- this.associationTablesPage = new AssociationTablesPage( customizer );
- addPage(this.associationTablesPage);
-
- this.joinColumnsPage = new JoinColumnsPage(customizer);
- addPage(this.joinColumnsPage);
-
- this.cardinalityPage = new CardinalityPage(customizer);
- addPage(this.cardinalityPage);
- }
-
- public boolean performFinish() {
- return true;
- }
-
- public ORMGenCustomizer getCustomizer (){
- return customizer;
- }
-
- public JpaProject getJpaProject(){
- return this.jpaProject;
- }
-
-// public Schema getDefaultSchema() {
-// return getJpaProject().getDefaultDbSchema();
-// }
-//
-// private boolean projectDefaultSchemaExists() {
-// return ( this.getDefaultSchema() != null);
-// }
-
- public HashMap<String, Object> getDataModel(){
- return this.associationDataModel;
- }
-
- public void updateTableNames(){
- IWizardPage[] pages = this.getPages();
- for( IWizardPage page : pages){
- ((NewAssociationWizardPage)page).updateWithNewTables();
- }
- }
-
- @SuppressWarnings("unchecked")
- public Association getNewAssociation(){
- String referrerTableName =getReferrerTableName();
- String referencedTableName = getReferencedTableName();
- List<String> referrerColNames = new ArrayList<String>();
- List<String> referencedColNames = new ArrayList<String>();
-
- String cardinality = (String)associationDataModel.get( NewAssociationWizard.ASSOCIATION_CADINALITY );
- if( cardinality.equals(Association.MANY_TO_MANY) ){
- return createManyToManyAssociation();
- }
-
- Object value = associationDataModel.get( NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1);
- if(value!=null){
- TreeMap<String, String> joinColumns = (TreeMap<String, String>)value;
- for( String pk : joinColumns.keySet()){
- referrerColNames.add(pk);
- referencedColNames.add( joinColumns.get(pk));
- }
- }
-
- /*if one-to-many then convert it to many-to-one to be consistent
- * with the associations computed from the db foreign keys.
- * Don't see at this point how one-to-many would
- * affect the generation.*/
- if( cardinality.equals(Association.ONE_TO_MANY) ){
- cardinality = Association.MANY_TO_ONE;
-
- String temp1 = referrerTableName;
- referrerTableName = referencedTableName;
- referencedTableName = temp1;
-
- List<String> temp2 = referrerColNames;
- referrerColNames = referencedColNames;
- referencedColNames = temp2;
- }
-
- Association association = null;
- association = new Association(this.customizer, referrerTableName, referrerColNames , referencedTableName, referencedColNames);
- association.setCardinality( cardinality );
- association.setCustom(true);
- return association;
- }
-
- @SuppressWarnings("unchecked")
- private Association createManyToManyAssociation() {
- String referrerTableName =getReferrerTableName();
- String joinTable = getJoinTableName();
- String referencedTableName = getReferencedTableName();
-
- List<String> referrerColNames = new ArrayList<String>();
- List<String> referrerJoinColNames = new ArrayList<String>();
- Object value = associationDataModel.get( NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1);
- if(value!=null){
- TreeMap<String, String> joinColumns = (TreeMap<String, String>)value;
- for( String pk : joinColumns.keySet()){
- referrerColNames.add(pk);
- referrerJoinColNames.add( joinColumns.get(pk));
- }
- }
-
- value = associationDataModel.get( NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2);
- List<String> referencedColNames = new ArrayList<String>();
- List<String> referencedJoinColNames = new ArrayList<String>();
- if(value!=null){
- TreeMap<String, String> joinColumns = (TreeMap<String, String>)value;
- for( String pk : joinColumns.keySet()){
- referencedJoinColNames.add(pk);
- referencedColNames.add( joinColumns.get(pk));
- }
- }
-
-
- Association association = null;
- association = new Association(this.customizer, referrerTableName, referrerColNames,
- referencedTableName, referencedColNames, joinTable, referrerJoinColNames, referencedJoinColNames);
- return association;
- }
-
- String getReferrerTableName(){
- return (String)associationDataModel.get(NewAssociationWizard.ASSOCIATION_REFERRER_TABLE);
- }
-
- String getReferencedTableName(){
- return (String)associationDataModel.get(NewAssociationWizard.ASSOCIATION_REFERENCED_TABLE);
- }
-
- String getJoinTableName(){
- return (String)associationDataModel.get(NewAssociationWizard.ASSOCIATION_JOIN_TABLE );
- }
-
- String getCardinality(){
- return (String)associationDataModel.get(NewAssociationWizard.ASSOCIATION_CADINALITY );
- }
-
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizardPage.java
deleted file mode 100644
index 68c328ac7b..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/NewAssociationWizardPage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.HashMap;
-
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-
-public abstract class NewAssociationWizardPage extends WizardPage {
-
- protected ORMGenCustomizer customizer;
-
- public NewAssociationWizardPage(ORMGenCustomizer customizer, String name) {
- super(name);
- this.customizer = customizer ;
- }
-
- protected HashMap<String, Object> getWizardDataModel(){
- return ((NewAssociationWizard)this.getWizard()).getDataModel();
- }
-
- protected String getReferrerTableName(){
- return ((NewAssociationWizard)getWizard()).getReferrerTableName();
- }
-
- protected String getReferencedTableName(){
- return ((NewAssociationWizard)getWizard()).getReferencedTableName();
- }
-
- protected String getJoinTableName(){
- return ((NewAssociationWizard)getWizard()).getJoinTableName();
- }
-
- protected String getCardinality(){
- return ((NewAssociationWizard)getWizard()).getCardinality() ;
- }
-
- public void updateWithNewTables() {
- }
-
- /**
- * Returns the helps system.
- * @return The platform's help system
- */
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
deleted file mode 100644
index c09c53d478..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.PlatformUI;
-
-public class PromptJPAProjectWizardPage extends WizardPage {
-
- private static String SELECT_PROJECT_PAGE_NAME = "SelectJPAProject"; //$NON-NLS-1$
- private Table projTable;
- private TableViewer projTableViewer;
- private static int PROJECT_NAME_COLUMN_INDEX = 0;
- private final String helpContextId;
-
- protected PromptJPAProjectWizardPage( final String helpContextId ) {
- super(SELECT_PROJECT_PAGE_NAME);
- setTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_selectJPAProject );
- setMessage( JptUiEntityGenMessages.GenerateEntitiesWizard_selectJPAProject_msg );
- this.helpContextId = helpContextId;
- }
-
- public void createControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 1;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- Label label = new Label( composite, SWT.NONE );
- label.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_selectJPAProject );
-
- projTableViewer = new TableViewer(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
- projTable = projTableViewer.getTable();
- GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- projTable.setLayoutData(gd);
-
- projTable.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- handleJpaProjectSelection();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- });
-
- projTableViewer = new TableViewer(projTable);
- projTableViewer.setLabelProvider(new ProjectTableLabelProvider());
- projTableViewer.setContentProvider(new ProjectTableContentProvider());
- fillJpaProjectList();
- setControl( composite );
- validate();
- }
-
- private void handleJpaProjectSelection() {
- if (projTable.getSelectionIndex() != -1) {
- TableItem item = projTable.getItem(projTable.getSelectionIndex());
- String projName = item.getText(0);
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
- JpaProject jpaProj = JptCorePlugin.getJpaProject( project );
- ((GenerateEntitiesFromSchemaWizard)getWizard()).setJpaProject(jpaProj);
- validate();
- }
- }
-
- private void fillJpaProjectList() {
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- List<String> projNames = new ArrayList<String>();
- for ( IProject project : projects )
- {
- JpaProject jpaProj = JptCorePlugin.getJpaProject( project );
- if ( jpaProj != null ) {
- projNames.add(project.getName());
- }
- }
- projTableViewer.setInput(projNames);
- }
-
- private void validate() {
- if (projTable.getSelectionIndex() != -1)
- setPageComplete(true);
- else
- setPageComplete(false);
- }
-
- @Override
- public final void performHelp()
- {
- PlatformUI.getWorkbench().getHelpSystem().displayHelp( this.helpContextId );
- }
-
- // inner classes
- private final class ProjectTableLabelProvider extends LabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex)
- {
- if (columnIndex == PROJECT_NAME_COLUMN_INDEX)
- return PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT);
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex)
- {
- assert element instanceof String;
- String projectName = (String)element;
- if (columnIndex == PROJECT_NAME_COLUMN_INDEX)
- return projectName;
- return null;
- }
- }
-
- private final class ProjectTableContentProvider implements IStructuredContentProvider
- {
- public Object[] getElements(Object inputElement){
- return ((Collection<?>) inputElement).toArray();
- }
-
- public void dispose(){}
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput){}
-
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SWTUtil.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SWTUtil.java
deleted file mode 100644
index 7e170d1989..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SWTUtil.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * Collection of utility methods to create SWT UI
- *
- */
-public class SWTUtil {
- /**
- * Set the layoutData of the input control to occupy specified number of columns
- * @param c
- * @param columns
- */
- public static void fillColumns(Control c, int columns){
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- c.setLayoutData(layoutData);
- return ;
- }
-
- public static void fillColumnsWithIndent(Control c, int columns, int indent){
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- layoutData.horizontalIndent = indent ;
- c.setLayoutData(layoutData);
- return ;
- }
-
- public static Label createLabel(Composite container, int span, String text) {
- Label label = new Label(container, SWT.NONE);
- label.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- label.setLayoutData(gd);
- return label;
- }
-
- /**
- * Create a new label which occupies one grid column
- * @param parent
- * @param text
- */
- public static Label newLabel(Composite parent, String text) {
- Label label = new Label( parent, SWT.NONE);
- label.setText( text );
- label.setLayoutData(new GridData());
- return label;
- }
-
- /**
- * Create a new label which occupies one grid column
- * @param parent
- * @param text
- */
- public static Label newLabelWithIndent(Composite parent, String text, int indent) {
- Label label = new Label( parent, SWT.NONE);
- label.setText( text );
- GridData layoutData = new GridData();
- layoutData.horizontalAlignment = SWT.BEGINNING;
- layoutData.verticalAlignment = SWT.TOP ;
- layoutData.horizontalIndent = indent ;
- label.setLayoutData(layoutData);
- return label;
- }
-
- /**
- * Creates a separator line. Expects a <code>GridLayout</code> with at least 1 column.
- *
- * @param composite the parent composite
- * @param nColumns number of columns to span
- */
- @SuppressWarnings("restriction")
- public static void createSeparator(Composite composite, int nColumns) {
- (new org.eclipse.jdt.internal.ui.wizards.dialogfields.Separator(
- SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(composite, nColumns, 5);
- }
-
-
- public static Button createButton(Composite container, int span, String text, int style) {
- Button btn = new Button(container, style);
- btn.setText(text);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- btn.setLayoutData(gd);
- return btn;
- }
-
- public static Combo createCombo(Composite container, int span ) {
- Combo combo = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- gd.grabExcessHorizontalSpace=true;
- gd.horizontalAlignment = SWT.FILL;
- combo.setLayoutData(gd);
- return combo;
- }
-
- public static Text createText(Composite container, int span ) {
- Text text = new Text(container, SWT.BORDER);
- GridData gd = new GridData();
- gd.horizontalSpan = span;
- gd.grabExcessHorizontalSpace=true;
- gd.horizontalAlignment = SWT.FILL;
- text.setLayoutData(gd);
- return text;
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SelectTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SelectTableDialog.java
deleted file mode 100644
index 3c8ca2b063..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/SelectTableDialog.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-
-/**
- * A database table selection dialog which allows user to filter tables by name
- */
-public class SelectTableDialog extends ElementListSelectionDialog {
-
- public SelectTableDialog(Shell shell){
- super(shell, new ILabelProvider(){
- public Image getImage(Object element) {
- return ImageRepository.getTableImage();
- }
-
- public String getText(Object element) {
- return element.toString();
- }
- public void addListener(ILabelProviderListener listener) {}
- public void dispose() {}
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {}
-
- });
- this.setTitle( JptUiEntityGenMessages.selectTableDlgTitle );//
- this.setMessage( JptUiEntityGenMessages.selectTableDlgDesc);//
- }
-
- public SelectTableDialog(Shell shell, Schema schema){
- this(shell);
-
- ArrayList<String> list = new ArrayList<String>();
- Iterator<Table> tablesIt = schema.tables();
- while (tablesIt.hasNext())
- {
- Table table = tablesIt.next();
- list.add(table.getName());
- }
- this.setElements( list.toArray() );
-
- }
-
- public SelectTableDialog(Shell shell, List<String> tableNames){
- this(shell);
- this.setElements( tableNames.toArray() );
- }
- public String getSelectedTable()
- {
- String tableName = (String)this.getFirstResult();
- return tableName ;
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableAssociationsWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableAssociationsWizardPage.java
deleted file mode 100644
index 066ad08244..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableAssociationsWizardPage.java
+++ /dev/null
@@ -1,757 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.fillColumns;
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.newLabel;
-import static org.eclipse.jpt.ui.internal.wizards.gen.SWTUtil.newLabelWithIndent;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.gen.internal.Association;
-import org.eclipse.jpt.gen.internal.AssociationRole;
-import org.eclipse.jpt.gen.internal.ORMGenColumn;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.gen.internal.util.DTPUtil;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.layout.FillLayout;
-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.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-public class TableAssociationsWizardPage extends WizardPage {
-
- private JpaProject jpaProject;
- private ORMGenCustomizer customizer ;
-
- private AssociationsListComposite associationList;
- private Association selectedAssociation;
- private Button deleteAssociationLink ;
- private Button createAssociationLink ;
-
- //Controls in Association Edit Panel
- private Composite associationsEditPanel ;
- private Button generateAssociationCheckBox;
- private Label cardinalityLabel ;
- private Combo cardinalityCombo ;
- /*whether to generate the referrer-->referenced role.*/
- private Button referrerRoleCheckBox;
- /*the name of the property in the referrer-->referenced role.*/
- private Label referrerRolePropertyLabel;
- private Text referrerRolePropertyField ;
- /*the cascade in the referrer-->referenced role.*/
- @SuppressWarnings("restriction")
- private StringButtonDialogField referrerRoleCascadeField;
- /*whether to generate the referenced->referrer role.*/
- private Button referencedRoleCheckBox;
- /*the name of the property in the referenced->referrer role.*/
- private Label referencedRolePropertyLabel;
- private Text referencedRolePropertyField ;
- /*the cascade in the referenced->referrer role.*/
- @SuppressWarnings("restriction")
- private StringButtonDialogField referencedRoleCascadeField;
- private Label joinConditionLabel;
- private Text joinConditionText;
-
- private Composite detailPanel ;
- private StackLayout detailPanelStatckLayout ;
- private Composite emptyPanel ;
-
- protected TableAssociationsWizardPage(JpaProject jpaProject ) {
- super("Table Associations"); //$NON-NLS-1$
- this.jpaProject = jpaProject;
- setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_title);
- setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_desc);
-
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
-
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 2 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_TABLE_ASSOCIATIONS);
-
- Label label = new Label(composite, SWT.NONE);
- label.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_label );
- GridData gd = new GridData();
- gd.horizontalSpan = 2;
- label.setLayoutData( gd );
-
- createAssociationsListPanel(composite);
- createAddDeleteButtons(composite, nColumns);
- SWTUtil.createSeparator(composite, nColumns);
-
- createDetailPanel(composite);
- setControl(composite);
-
- composite.layout(true);
- this.setPageComplete( true);
-
- }
-
- private void createAddDeleteButtons(Composite composite, int columns) {
-
- Composite c = new Composite( composite, SWT.NONE);
- fillColumns(c, 1);
- c.setLayout( new GridLayout(1,true) );
-
- createAssociationLink = new Button(c, SWT.NONE);
- createAssociationLink.setToolTipText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_newAssoc );
- createAssociationLink.setImage( ImageRepository.getAddButtonImage() );
- createAssociationLink.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- launchNewAssociationsWizard();
- }
-
- });
-
- deleteAssociationLink = new Button(c, SWT.NONE);
- deleteAssociationLink.setForeground( new Color(Display.getDefault(), 0,0,255));
- deleteAssociationLink.setImage( ImageRepository.getDeleteButtonImage() );
- deleteAssociationLink.setToolTipText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_delAssoc );
- deleteAssociationLink.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- Association association = associationList.getSelectedAssociation();
- if( association != null ){
- ORMGenCustomizer customizer = getCustomizer();
- customizer.deleteAssociation(association);
- List<Association> associations = customizer.getAssociations();
- associationList.updateAssociations(associations);
- if( associations.size()==0 ){
- hideAssociationDetail();
- }
- }
- }
- });
- deleteAssociationLink.setEnabled(false);
-
- }
-
- private void createGenerateAssociationCheckbox(Composite composite, int columns) {
- generateAssociationCheckBox = new Button(composite, SWT.CHECK);
- generateAssociationCheckBox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_genAssoc);
- generateAssociationCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- Association association = associationList.getSelectedAssociation();
- if( association == null )
- return;
- association.setGenerated(generateAssociationCheckBox.getSelection());
-
- updateAssociationEditPanel(association);
- associationList.updateSelectedAssociation();
- }
-
- });
-
- fillColumns(generateAssociationCheckBox, columns-1);
- newLabel(composite, "");
- }
-
- @SuppressWarnings("restriction")
- private void createGenerateReferrerRoleControls(Composite parent, int columns) {
- referrerRoleCheckBox = new Button(parent, SWT.CHECK);
- referrerRoleCheckBox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_entityRef );
- referrerRoleCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- boolean generate = referrerRoleCheckBox.getSelection();
- //referrerRolePropertyField.setEditable( generate );
- referrerRolePropertyLabel.setEnabled( generate );
- referrerRolePropertyField.setEnabled( generate );
- referrerRoleCascadeField.setEnabled(generate);
-
- //If both referencedRoleCheckBox and referencedRoleCheckBox unchecked,
- //the association itself shouldn't be generated
- if( !generate && !referencedRoleCheckBox.getSelection()){
- generateAssociationCheckBox.setSelection(false);
- cardinalityLabel.setEnabled( false );
- cardinalityCombo.setEnabled(false);
- referrerRoleCheckBox.setEnabled(false);
- referencedRoleCheckBox.setEnabled(false);
- }
-
- directionalityCheckBoxChanged( );
-
- if( generate ){
- AssociationRole role = selectedAssociation.getReferrerRole();
- referrerRolePropertyField.setText( role.getPropertyName() );
- }
- }
-
- });
-
- SWTUtil.fillColumnsWithIndent(referrerRoleCheckBox , columns-1, 20 );
- newLabel(parent, "");//$NON-NLS-1$
-
- referrerRolePropertyLabel = newLabelWithIndent( parent, JptUiEntityGenMessages.property, 40 ); //$NON-NLS-1$
- referrerRolePropertyField = new Text( parent, SWT.BORDER);
- fillColumns(referrerRolePropertyField, 2);
- referrerRolePropertyField.addModifyListener(new ModifyListener(){
- @SuppressWarnings("deprecation")
- public void modifyText(ModifyEvent e) {
- if( selectedAssociation.getReferrerRole() == null )
- return;
- String fieldName = referrerRolePropertyField.getText();
- IStatus status = JavaConventions.validateFieldName( fieldName );
- if( !status.matches(IStatus.ERROR) ){
- selectedAssociation.getReferrerRole().setPropertyName(fieldName);
- }
- updateStatus(status);
- }
- });
-
- Label label = new Label( parent, SWT.NONE);
- label.setText( "" );//$NON-NLS-1$
- label.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
-
- referrerRoleCascadeField = new StringButtonDialogField( new IStringButtonAdapter(){
- public void changeControlPressed(DialogField field) {
- if( editCascade( selectedAssociation.getReferrerRole() )){
- referrerRoleCascadeField.setText(selectedAssociation.getReferrerRole().getCascade());
- }
- }
- }) ;
- referrerRoleCascadeField.setLabelText( JptUiEntityGenMessages.cascade ); //$NON-NLS-1$
- referrerRoleCascadeField.setButtonLabel(""); //$NON-NLS-1$
- referrerRoleCascadeField.doFillIntoGrid(parent, 3);
- referrerRoleCascadeField.getTextControl(parent).setEditable(false);
- int maxFieldWidth = convertWidthInCharsToPixels(40);
- LayoutUtil.setWidthHint(referrerRoleCascadeField.getTextControl(null), maxFieldWidth );
- Button btn = referrerRoleCascadeField.getChangeControl(null);
- GridData data = (GridData)btn.getLayoutData();
- btn.setImage( ImageRepository.getBrowseButtonImage() );
- data.horizontalAlignment = SWT.BEGINNING;
- data.widthHint = 30;
- btn.setLayoutData(data);
-
- Label labelCtrl = referrerRoleCascadeField.getLabelControl(parent);
- data = (GridData)labelCtrl.getLayoutData();
- data.horizontalIndent = 40 ;
- labelCtrl.setLayoutData(data);
-
-
- label = new Label( parent, SWT.NONE);
- label.setText( "" );//$NON-NLS-1$
- label.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
-
- }
-
-
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if( visible ){
- hideAssociationDetail();
- updateAssociationsListPanel();
- }
- }
-
- private void hideAssociationDetail( ){
- this.detailPanelStatckLayout.topControl = emptyPanel;
- this.detailPanel.layout();
- this.detailPanel.getParent().layout();
- }
-
- /**
- * Updates the status line and the OK button according to the given status
- *
- * @param status status to apply
- */
- @SuppressWarnings("restriction")
- protected void updateStatus(IStatus status) {
- setPageComplete(!status.matches(IStatus.ERROR));
-
- StatusUtil.applyToStatusLine(this, status);
- if( status.getCode() == Status.OK ){
- setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_assocPage_desc);
- }
- }
-
- @SuppressWarnings("restriction")
- private void createGenerateReferencedRoleControls(Composite parent, int columns) {
- referencedRoleCheckBox = new Button(parent, SWT.CHECK);
- referencedRoleCheckBox.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_setRef );
- referencedRoleCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- boolean generate = referencedRoleCheckBox.getSelection();
- referencedRolePropertyLabel.setEnabled( generate);
- referencedRolePropertyField.setEnabled( generate);
- referencedRoleCascadeField.setEnabled(generate);
-
- if( !generate && !referrerRoleCheckBox.getSelection()){
- generateAssociationCheckBox.setSelection(false);
- cardinalityCombo.setEnabled(false);
- referrerRoleCheckBox.setEnabled(false);
- referencedRoleCheckBox.setEnabled(false);
- }
- directionalityCheckBoxChanged();
- if( generate ){
- AssociationRole role = selectedAssociation.getReferencedRole();
- referencedRolePropertyField.setText( role.getPropertyName() );
- }
- }
-
- });
-
- SWTUtil.fillColumnsWithIndent( referencedRoleCheckBox , columns-1, 20 );
- newLabel(parent, "");//$NON-NLS-1$
-
- referencedRolePropertyLabel = SWTUtil.newLabelWithIndent(parent, JptUiEntityGenMessages.property, 40 ); //$NON-NLS-1$
-
- referencedRolePropertyField = new Text( parent, SWT.BORDER);
- fillColumns(referencedRolePropertyField, 2);
- referencedRolePropertyField.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e) {
- if( selectedAssociation.getReferencedRole() == null )
- return ;
-
- String fieldName = referencedRolePropertyField.getText();
- IStatus status = JavaConventions.validateIdentifier(fieldName,
- JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
- if( !status.matches(IStatus.ERROR) ){
- if( !fieldName.equals(selectedAssociation.getReferencedRole().getPropertyName()) )
- selectedAssociation.getReferencedRole().setPropertyName(fieldName);
- }
- updateStatus(status);
- }
- });
-
-
- Label label = new Label( parent, SWT.NONE);
- label.setText( "" );//$NON-NLS-1$
- label.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
-
-
- referencedRoleCascadeField = new StringButtonDialogField( new IStringButtonAdapter(){
- public void changeControlPressed(DialogField field) {
- if( editCascade( selectedAssociation.getReferencedRole() ) ){
- referencedRoleCascadeField.setText( selectedAssociation.getReferencedRole().getCascade() );
- }
- }
- }) ;
- referencedRoleCascadeField.setLabelText( JptUiEntityGenMessages.cascade ); //$NON-NLS-1$
- referencedRoleCascadeField.setButtonLabel(""); //$NON-NLS-1$
- referencedRoleCascadeField.doFillIntoGrid(parent, 3);
- referencedRoleCascadeField.getTextControl(parent).setEditable( false);
- int maxFieldWidth = convertWidthInCharsToPixels(40);
- LayoutUtil.setWidthHint(referencedRoleCascadeField.getTextControl(null), maxFieldWidth );
- Button btn = referencedRoleCascadeField.getChangeControl(null);
- btn.setImage( ImageRepository.getBrowseButtonImage() );
- GridData data = (GridData)btn.getLayoutData();
- data.horizontalAlignment = SWT.BEGINNING;
- data.widthHint = 30;
- btn.setLayoutData(data);
-
- Label labelCtrl = referencedRoleCascadeField.getLabelControl(parent);
- data = (GridData)labelCtrl.getLayoutData();
- data.horizontalIndent = 40 ;
- labelCtrl.setLayoutData(data);
-
- label = new Label( parent, SWT.NONE);
- label.setText( "" );//$NON-NLS-1$
- label.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
-
- }
-
- private void createDetailPanel(Composite composite ) {
-
- this.detailPanel = new Composite( composite, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.grabExcessVerticalSpace = false;
- this.detailPanel.setLayoutData(gd);
- this.detailPanelStatckLayout = new StackLayout();
- this.detailPanel.setLayout( this.detailPanelStatckLayout );
-
- emptyPanel = new Composite( detailPanel, SWT.NONE);
- emptyPanel.setLayoutData(new GridData());
- detailPanelStatckLayout.topControl = emptyPanel;
- detailPanel.layout();
-
- composite.layout();
- }
-
-
- private Composite createAssociationsEditPanel(Composite composite, int columns) {
- Composite parent = new Composite( composite, SWT.NONE);
- fillColumns(parent, 4);
-
- createGenerateAssociationCheckbox(parent,columns);
- int nColumns= 4 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- parent.setLayout(layout);
-
- //Cardinality
- cardinalityLabel = new Label(parent, SWT.NONE);
- cardinalityLabel.setText( JptUiEntityGenMessages.cardinality);
- GridData gd = new GridData();
- gd.horizontalIndent = 20;
- cardinalityLabel.setLayoutData( gd );
-
- cardinalityCombo = new Combo(parent, SWT.SINGLE | SWT.READ_ONLY );
-
- fillColumns(cardinalityCombo, 1);
-
- cardinalityCombo.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- selectedAssociation.setCardinality( cardinalityCombo.getText());
- associationList.updateSelectedAssociation();
- }
- });
-
- //Adding a filler column
- Label label = new Label( parent, SWT.NONE);
- label.setText( "");//$NON-NLS-1$
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- label.setLayoutData(layoutData);
-
- //Table join condition
- joinConditionLabel = newLabelWithIndent(parent, JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_tableJoin, 20 );
-
- joinConditionText = new Text( parent, SWT.MULTI | SWT.BORDER );
- joinConditionText.setEditable(false);
- joinConditionText.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_joinedWhen);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- layoutData.verticalAlignment = SWT.TOP;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- layoutData.heightHint = 50;
- joinConditionText.setLayoutData(layoutData);
- newLabel(parent, "");//$NON-NLS-1$
-
- //Generate UI controls for ReferrerRole
- createGenerateReferrerRoleControls(parent, columns);
-
- //Generate UI controls for ReferencedRole
- createGenerateReferencedRoleControls(parent, columns);
-
-
- return parent;
- }
-
- public boolean editCascade(AssociationRole role) {
- CascadeDialog dlg = CascadeDialog.create(role);
- if (dlg.open() == Window.CANCEL ) {
- return false;
- }
-
- return true;
- }
-
- private void createAssociationsListPanel(Composite parent) {
- Composite composite = new Composite( parent, SWT.NULL );
- composite.setLayout( new FillLayout());
- composite.setBackground(new Color(Display.getDefault(),255, 0,0) );
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = 1;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = false;
- layoutData.grabExcessVerticalSpace = true;
- layoutData.widthHint = 400;
- layoutData.heightHint = 400;
- composite.setLayoutData(layoutData);
-
- associationList = new AssociationsListComposite(composite, this);
- }
-
- private void launchNewAssociationsWizard() {
- ORMGenCustomizer customizer = getCustomizer();
- NewAssociationWizard wizard = new NewAssociationWizard(this.jpaProject, customizer );
-
- WizardDialog dialog = new WizardDialog( this.getShell(), wizard);
- dialog.create();
- int returnCode = dialog.open();
- if (returnCode == Window.OK) {
- Association association = wizard.getNewAssociation();
- if( association !=null ){
- customizer.addAssociation(association);
- updateForeignKeyColumnGenProperty(association);
- updateAssociationsListPanel();
- }
- }
- }
- /**
- * For user created association:
- * If association is to be generated, no need to generate the getter/setter for the column itself
- */
- private void updateForeignKeyColumnGenProperty(Association association) {
- //Need to process MANY_TO_ONE only since the the associations list are optimized to have MANY_TO_ONE
- if( association.isCustom() && association.getCardinality().equals( Association.MANY_TO_ONE ) ){
- boolean generateColumn = !association.isGenerated();
- //The "MANY" side DB table
- //ORMGenTable table1 = association.getReferrerTable();
- //The "ONE" side DB table
- //ORMGenTable table2 = association.getReferencedTable();
- //The list of foreign key columns in the MANY side, should not be generated
- //The list of primary keys in the ONE side, will be generated
- //List<ORMGenColumn> list2 = association.getReferencedColumns();
- List<ORMGenColumn> list1 = association.getReferrerColumns();
- for(ORMGenColumn c : list1 ){
- if( c.isGenerated() != generateColumn){
- if( !generateColumn && c.getDbColumn().isPartOfPrimaryKey() ){
- continue;
- }
- c.setGenerated(generateColumn);
- c.setInsertable(generateColumn);
- c.setUpdateable(generateColumn);
- }
- }
- }
- }
-
- private void updateAssociationsListPanel() {
- ORMGenCustomizer customizer = getCustomizer();
- //If user changed the connection or schema
- if( this.customizer != customizer ){
- this.customizer = customizer;
- }
- List<Association> associations = customizer.getAssociations();
- this.associationList.updateAssociations( associations );
- }
-
- @SuppressWarnings("restriction")
- public void updateAssociationEditPanel(Association association) {
- this.selectedAssociation = association;
-
- boolean enabled = association.isCustom();
- this.deleteAssociationLink.setEnabled(enabled);
-
- //Create and display the associationsEditPanel if it was hidden before
- if( associationsEditPanel == null ){
- associationsEditPanel = this.createAssociationsEditPanel(this.detailPanel, 4);
- }
- this.detailPanelStatckLayout.topControl = associationsEditPanel;
- this.detailPanel.layout();
- this.detailPanel.getParent().layout();
-
- //Update the UI controls from the model
- String table1Name = association.getReferrerTableName();
- String table2Name = association.getReferencedTableName();
- String joinTableName = association.getJoinTableName();
-
- boolean isGenerated = association.isGenerated();
- this.generateAssociationCheckBox.setSelection(isGenerated);
- this.referrerRolePropertyLabel.setEnabled( isGenerated );
- this.referrerRolePropertyField.setEnabled( isGenerated );
- this.referrerRoleCheckBox.setEnabled( isGenerated );
- this.referencedRolePropertyLabel.setEnabled( isGenerated );
- this.referencedRolePropertyField.setEnabled( isGenerated );
- this.referencedRoleCheckBox.setEnabled( isGenerated );
- this.cardinalityLabel.setEnabled(isGenerated);
- this.cardinalityCombo.setEnabled(isGenerated);
- this.joinConditionLabel.setEnabled( isGenerated );
- this.joinConditionText.setEnabled( isGenerated );
-
- String cardinality = association.getCardinality();
- if( Association.MANY_TO_MANY.equals( cardinality ) ){
- cardinalityCombo.removeAll();
- cardinalityCombo.add( Association.MANY_TO_MANY);
- }else{
- cardinalityCombo.removeAll();
- cardinalityCombo.add( Association.MANY_TO_ONE);
- cardinalityCombo.add( Association.ONE_TO_ONE);
- }
-
- cardinalityCombo.setText(cardinality);
- cardinalityCombo.setEnabled(enabled);
-
- String text = null;
- //if MTM
- if( Association.MANY_TO_MANY.equals( cardinality ) ){
- text = String.format( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_setRef, table2Name, table1Name);
- }else{
- text = String.format( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_entityRef, table2Name, table1Name);
- }
- this.referrerRoleCheckBox.setText(text);
-
- //if OTO
- if( Association.ONE_TO_ONE.equals( cardinality ) ){
- text = String.format( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_entityRef, table1Name, table2Name);
- }else{
- text = String.format( JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_setRef, table1Name, table2Name);
- }
- this.referencedRoleCheckBox.setText(text);
-
- //AssociationRole properties
- AssociationRole referrerRole = association.getReferrerRole();
- if( referrerRole != null){
- this.referrerRoleCheckBox.setSelection( true );
- this.referrerRolePropertyField.setEditable(true);
- this.referrerRolePropertyField.setText(referrerRole.getPropertyName());
- this.referrerRoleCascadeField.setEnabled(true);
- String cascade = referrerRole.getCascade();
- if( cascade!=null )
- this.referrerRoleCascadeField.setText( cascade );
-
- //if MTO:
- if( Association.MANY_TO_ONE.equals( cardinality ) ){
- this.referrerRoleCheckBox.setEnabled( false );
- }
- }else{
- this.referrerRoleCheckBox.setSelection( false );
- this.referrerRolePropertyLabel.setEnabled(false);
- this.referrerRolePropertyField.setEditable(false);
- this.referrerRolePropertyField.setText("");
- this.referrerRoleCascadeField.setEnabled(false);
- }
-
- AssociationRole referencedRole = association.getReferencedRole();
- if( referencedRole != null){
- this.referencedRoleCheckBox.setSelection( true );
- this.referencedRolePropertyLabel.setEnabled(true);
- this.referencedRolePropertyField.setEditable(true);
- this.referencedRolePropertyField.setText(referencedRole.getPropertyName());
- this.referencedRoleCascadeField.setEnabled(true);
- String cascade = referencedRole.getCascade();
- if( cascade!=null )
- this.referencedRoleCascadeField.setText(cascade);
- }else{
- this.referencedRoleCheckBox.setSelection( false );
- this.referencedRolePropertyLabel.setEnabled(false);
- this.referencedRolePropertyField.setEditable(false);
- this.referencedRolePropertyField.setText("");
- this.referencedRoleCascadeField.setEnabled(false);
- }
-
- //Join conditions
- updateJoinConditions(association, table1Name, table2Name, joinTableName);
- }
-
- private void updateJoinConditions(Association association,
- String table1Name, String table2Name, String joinTableName) {
- String text = "%s";
- if( joinTableName == null ){
- StringBuilder strText = new StringBuilder();
- //text = JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_joinedWhen;
- List<String> columnList1 = association.getReferrerColumnNames() ;
- List<String> columnList2 = association.getReferencedColumnNames();
- for( int i=0; i < columnList1.size(); i++){
- strText.append( table1Name + "." + columnList1.get(i) );//$NON-NLS-1$
- strText.append( "=" );//$NON-NLS-1$
- strText.append( table2Name + "." + columnList2.get(i) );//$NON-NLS-1$
- if( i < columnList1.size()-1 )
- strText.append( "\n AND " );//$NON-NLS-1$
- }
- joinConditionText.setText( String.format( text , strText.toString()) );
- }else{
- StringBuilder strText = new StringBuilder();
- //text = JptUiEntityGenMessages.GenerateEntitiesWizard_assocEditor_joinedWhen;
- List<String> columnList1 = association.getReferrerColumnNames() ;
- List<String> joinColumnList1 = association.getReferrerJoinColumnNames() ;
- for( int i=0; i < columnList1.size(); i++){
- strText.append( table1Name + "." + columnList1.get(i) );//$NON-NLS-1$
- strText.append( "=" );//$NON-NLS-1$
- strText.append( joinTableName + "." + joinColumnList1.get(i) );
- strText.append( "\n AND " );//$NON-NLS-1$
- }
-
- List<String> joinTableColumnList2 = association.getReferencedJoinColumnNames();
- List<String> columnList2 = association.getReferencedColumnNames();
- for( int i=0; i < joinTableColumnList2.size(); i++){
- strText.append( joinTableName + "." + joinTableColumnList2.get(i) );
- strText.append( "=" );//$NON-NLS-1$
- strText.append( table2Name + "." + columnList2.get(i) );//$NON-NLS-1$
- if( i < joinTableColumnList2.size()-1 )
- strText.append( "\n AND " );//$NON-NLS-1$
- }
-
- joinConditionText.setText( String.format( text , strText.toString()) );
-
- }
- }
-
- /**
- * Called when one of referrerRoleCheckBox or referencedRoleCheckBox
- * changes value.
- *
- */
- private void directionalityCheckBoxChanged() {
- String dir;
- if (referrerRoleCheckBox.getSelection()) {
- dir = referencedRoleCheckBox.getSelection() ? Association.BI_DI : Association.NORMAL_DI;
- } else {
- if (referencedRoleCheckBox.getSelection()) {
- dir = Association.OPPOSITE_DI;
- } else {
- dir = null;
- }
- }
- if (dir != null) {
- selectedAssociation.setDirectionality(dir);
- } else {
- selectedAssociation.setGenerated(false);
- }
-
- this.associationList.updateSelectedAssociation();
- }
-
- private ORMGenCustomizer getCustomizer(){
- GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard();
- return wizard.getCustomizer();
- }
-
-
- @Override
- public final void performHelp()
- {
- this.getHelpSystem().displayHelp( GenerateEntitiesFromSchemaWizard.HELP_CONTEXT_ID );
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableFigure.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableFigure.java
deleted file mode 100644
index c4462f4fa6..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableFigure.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.Figure;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.GridLayout;
-import org.eclipse.draw2d.Label;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-
-/**
- * A draw2D figure representing a database table
- *
- */
-public class TableFigure extends Figure {
- public static Color tableColor = new Color(null,220,232,241);
- public static Font tableFont = new Font(null, "Arial", 8, SWT.NONE);
- public static Color disabledColor = ColorConstants.white;
- public static Color borderColor = new Color( null, 14,66,115);
-
- public static final int OUTLINE_CORNER_RADIUS = 6;
-
- public TableFigure(String name) {
- GridLayout gl = new GridLayout();
- gl.marginHeight = 2;
- gl.marginWidth = 10;
- setLayoutManager(gl);
-
- setBorder(new LineBorder(tableColor,0));
- setBackgroundColor(tableColor);
- setOpaque(true);
- setSize(150, 20);
-
- Label nameLabel = new Label("", ImageRepository.getTableObjImage());
- nameLabel.setFont(tableFont);
- nameLabel.setText(name);
- nameLabel.setForegroundColor(borderColor);
- nameLabel.setLabelAlignment(PositionConstants.CENTER);
- add(nameLabel);
- }
-
- protected void paintClientArea(Graphics graphics)
- {
- super.paintClientArea(graphics);
- graphics.pushState();
- Rectangle r = getBounds().getCopy();
- graphics.drawRoundRectangle(r.expand(new Insets(-1, -1, -2, -2)),
- OUTLINE_CORNER_RADIUS, OUTLINE_CORNER_RADIUS );
- graphics.popState();
- }
-
- public void setEnabled(boolean enabled ) {
- super.setEnabled(enabled);
- if( enabled ){
- setBackgroundColor(tableColor);
- }else{
- setBackgroundColor(disabledColor);
- }
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableGenPanel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableGenPanel.java
deleted file mode 100644
index 63ed51bed3..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TableGenPanel.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.gen.internal.ORMGenTable;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * The UI panel for setting the default and specific
- * table entity generation properties.
- *
- */
-class TableGenPanel
-{
- WizardPage wizardPage ;
-
- private Text classNameField; // used in setting individual table/entity generation only
-
- private Combo idGeneratorCombo;
- private Text sequenceNameField;
-
- private Button entityAccessField;
- private Button entityAccessProperty;
- private Button associationFetchDefault;
- private Button associationFetchEager;
- private Button associationFetchLazy;
-
- private Button collectionTypeSet;
- private Button collectionTypeList;
-
- private Button generateOptionalAnnotations;
-
- private Label sequenceNameNoteLabel;
-
- private boolean isUpdatingControls;
-
- private ORMGenTable mTable;
-
- private boolean isDefaultTable = false;
-
- private static Color NOTE_LABEL_COLOR = new Color( Display.getDefault(), 102,102,102);
-
- public TableGenPanel(Composite parent, int columns , boolean isDefaultTable, WizardPage wizardPage ){
- super();
- this.wizardPage = wizardPage;
- this.isDefaultTable = isDefaultTable;
- createTableMappingPropertiesGroup(parent, columns);
- SWTUtil.createLabel(parent, 4, ""); //$NON-NLS-1$
- }
-
- protected void createTableMappingPropertiesGroup(Composite composite, int columns) {
- Group parent = new Group(composite, SWT.NONE );
- parent.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_tableMapping);
- parent.setLayout(new GridLayout(columns, false));
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- parent.setLayoutData(layoutData);
-
- createClassNameControl(parent, columns);
-
- createIdGeneratorControls(parent, columns);
- createEntityAccessControls(parent, columns);
-
- //AssociationFetch and CollectionType only available for default table generation
- if ( isDefaultTable ) {
- createAssociationFetchControls(parent, columns);
- createCollectionTypeControls(parent, columns);
- createGenerateOptionalAnnotationControls(parent, columns);
- }
- }
-
- private void createGenerateOptionalAnnotationControls(Group parent, int columns) {
- SWTUtil.createLabel(parent, 1, "");
- generateOptionalAnnotations = new Button(parent, SWT.CHECK );
- generateOptionalAnnotations.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_genOptionalAnnotations);
- generateOptionalAnnotations.setToolTipText(JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_genOptionalAnnotations_desc);
-
- GridData gd = new GridData();
- gd.horizontalSpan = columns-1;
- gd.horizontalIndent = 3 ;
- generateOptionalAnnotations.setLayoutData(gd);
- generateOptionalAnnotations.addSelectionListener(new SelectionListener(){
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- boolean selected = generateOptionalAnnotations.getSelection();
- mTable.setGenerateDDLAnnotations(selected);
- }
- });
- }
-
- private void createClassNameControl(Composite parent, int columns) {
- //Customize class name for specific table only
- if ( !isDefaultTable ) {
- SWTUtil.createLabel( parent, 1 , JptUiEntityGenMessages.GenerateEntitiesWizard_tablePanel_className );
-
- classNameField = new Text(parent, SWT.SINGLE | SWT.BORDER );
- //mPackageNameField.setEditable(false);
- SWTUtil.fillColumns(classNameField,3);
- classNameField.addModifyListener(new ModifyListener(){
- @SuppressWarnings({ "deprecation" })
- public void modifyText(ModifyEvent e) {
- if (e.getSource() == null || !isUpdatingControls) {
- String className = classNameField.getText();
- IStatus status = JavaConventions.validateJavaTypeName( className );
- if( !status.matches(IStatus.ERROR) ){
- mTable.setClassName( className );
- wizardPage.setErrorMessage(null);
- }else{
- wizardPage.setErrorMessage(status.getMessage());
- }
- }
- }
- });
- }
- }
-
- class AssociationFetchListener implements SelectionListener{
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!isUpdatingControls) {
- Button radioBtn = (Button)e.getSource();
- mTable.setDefaultFetch( radioBtn.getData().toString());
- }
- }
- }
-
- private void createAssociationFetchControls(Composite composite, int columns) {
- SWTUtil.createLabel(composite, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_fetch );
-
- Composite parent = new Composite( composite, SWT.NONE);
- parent.setLayout(new RowLayout());
- SWTUtil.fillColumns( parent , 3);
- associationFetchDefault = new Button( parent, SWT.RADIO );
- associationFetchDefault.setText( "Default");
- associationFetchDefault.setData( ORMGenTable.DEFAULT_FETCH );
-
- associationFetchEager = new Button( parent, SWT.RADIO );
- associationFetchEager.setText( "&Eager");
- associationFetchEager.setData( ORMGenTable.EAGER_FETCH );
-
- associationFetchLazy = new Button( parent, SWT.RADIO );
- associationFetchLazy.setText( "La&zy");
- associationFetchLazy.setData( ORMGenTable.LAZY_FETCH );
-
- AssociationFetchListener associationFetchListener = new AssociationFetchListener();
- associationFetchDefault.addSelectionListener( associationFetchListener );
- associationFetchLazy.addSelectionListener( associationFetchListener );
- associationFetchEager.addSelectionListener( associationFetchListener );
- }
-
- class CollectionTypeListener implements SelectionListener {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!isUpdatingControls) {
- Button radioBtn = (Button)e.getSource();
- mTable.setDefaultCollectionType( radioBtn.getData().toString());
- }
- }
- }
-
- private void createCollectionTypeControls(Composite composite, int columns) {
- SWTUtil.createLabel(composite, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_collType );
-
- Composite parent = new Composite( composite, SWT.NONE);
- parent.setLayout(new RowLayout());
- SWTUtil.fillColumns( parent , 3);
-
- this.collectionTypeSet = new Button( parent, SWT.RADIO);
- this.collectionTypeSet.setText( "java.util.Se&t");
- this.collectionTypeSet.setData( ORMGenTable.SET_COLLECTION_TYPE );
- this.collectionTypeList = new Button( parent, SWT.RADIO);
- this.collectionTypeList.setText("java.util.&List");
- this.collectionTypeList.setData(ORMGenTable.LIST_COLLECTION_TYPE);
-
- CollectionTypeListener collectionTypeListener = new CollectionTypeListener();
- collectionTypeList.addSelectionListener( collectionTypeListener );
- collectionTypeSet.addSelectionListener( collectionTypeListener );
- }
-
-
- public void setORMGenTable(ORMGenTable table) {
- mTable = table;
-
- isUpdatingControls = true;
-
- try {
- //ClassNameField is not available for default table
- if(classNameField!= null )
- classNameField.setText( mTable.getClassName() );
-
- final List<String> schemes = this.mTable.getCustomizer().getAllIdGenerators();
- String[] values = new String[schemes.size()];
- schemes.toArray(values);
- idGeneratorCombo.setItems( values );
- String idGenerator = mTable.getIdGenerator();
- idGeneratorCombo.setText( idGenerator);
-
- boolean isSequence = this.mTable.getCustomizer().getSequenceIdGenerators().contains(idGenerator);
- String sequenceName = mTable.isDefaultsTable() ? mTable.getSequence() : mTable.getFormattedSequence();
- sequenceName = ( sequenceName == null ? "" : sequenceName );
- sequenceNameField.setText( sequenceName );
- if ( isSequence ) {
- sequenceNameField.setEnabled(true);
- sequenceNameNoteLabel.setEnabled(true);
- } else {
- sequenceNameField.setEnabled(false);
- sequenceNameNoteLabel.setEnabled(false);
- }
-
- String access = mTable.getAccess() ;
- if ( ORMGenTable.FIELD_ACCESS.equals( access ) ) {
- this.entityAccessField.setSelection( true );
- this.entityAccessProperty.setSelection( false );
- } else {
- this.entityAccessProperty.setSelection( true );
- this.entityAccessField.setSelection( false );
- }
-
- if (associationFetchLazy != null && associationFetchEager != null ) {
- String defaultFetch = mTable.getDefaultFetch();
- //reset all three buttons
- associationFetchDefault.setSelection(false);
- associationFetchEager.setSelection(false);
- associationFetchLazy.setSelection(false);
- if( ORMGenTable.DEFAULT_FETCH.equals( defaultFetch ) )
- associationFetchDefault.setSelection(true);
- else if( ORMGenTable.EAGER_FETCH.equals( defaultFetch ) )
- associationFetchEager.setSelection(true);
- else
- associationFetchLazy.setSelection(true);
- }
-
- //DefaultTable only
- if (collectionTypeList != null) {
- String cType = mTable.getDefaultCollectionType();
- if ( ORMGenTable.LIST_COLLECTION_TYPE.equals( cType ) ) {
- this.collectionTypeList.setSelection( true );
- this.collectionTypeSet.setSelection( false );
- } else {
- this.collectionTypeSet.setSelection( true );
- this.collectionTypeList.setSelection( false );
- }
-
- this.generateOptionalAnnotations.setSelection( mTable.isGenerateDDLAnnotations());
- }
-
- } catch (Exception e) {
- JptUiPlugin.log(e);
- }
-
- isUpdatingControls = false;
- }
-
- private void createIdGeneratorControls(Composite parent, int columns) {
- SWTUtil.createLabel(parent, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_keyGen );
-
- idGeneratorCombo = new Combo(parent,SWT.SINGLE | SWT.READ_ONLY);
- SWTUtil.fillColumns(idGeneratorCombo, 3);
-
- idGeneratorCombo.addSelectionListener( new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- if (isUpdatingControls) {
- return;
- }
-
- idGenChanged();
- }});
-
- SWTUtil.createLabel(parent, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_sequence );
- sequenceNameField = new Text( parent, SWT.SINGLE | SWT.BORDER );
-
- SWTUtil.fillColumns(sequenceNameField, 3);
- sequenceNameField.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e) {
- if (e.getSource() == null || !isUpdatingControls) {
-
- if ( idGeneratorCombo.getText().equals("sequence")) { //$NON-NLS-1$
- String sequenceName = sequenceNameField.getText();
- if ( sequenceName.toLowerCase().indexOf("$table") >= 0 || //$NON-NLS-1$
- sequenceName.toLowerCase().indexOf("$pk") >= 0 ) { //$NON-NLS-1$
- sequenceName = convertVarToLowerCase("$table", sequenceName); //$NON-NLS-1$
- sequenceName = convertVarToLowerCase("$pk", sequenceName); //$NON-NLS-1$
- }
- if ( sequenceName.trim().length() != 0 ) {
- mTable.setSequence( sequenceName );
- } else{
- mTable.setSequence( "" ); //$NON-NLS-1$
- }
- }
- }
- }
-
- private String convertVarToLowerCase(String var, String sequenceName) {
- int n = sequenceName.toLowerCase().indexOf( var );
- if( n==0 ) {
- return var + sequenceName.substring( var.length());
- } else if( n >0 ) {
- return sequenceName.substring(0,n) + var + sequenceName.substring( n + var.length());
- }
- return sequenceName;
- }
- });
-
- SWTUtil.newLabel(parent, "");//$NON-NLS-1$
- sequenceNameNoteLabel = new Label(parent, SWT.NONE);
- String text =String.format( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_sequenceNote,
- ORMGenTable.TABLE_SEQ_PATTERN, ORMGenTable.PK_SEQ_PATTERN);
- sequenceNameNoteLabel.setText( text ) ;
- sequenceNameNoteLabel.setEnabled(false);
- SWTUtil.fillColumns( sequenceNameNoteLabel, 3);
- }
-
- private void idGenChanged() {
- String scheme = idGeneratorCombo.getText();
- mTable.setIdGenerator(scheme);
-
- boolean isSequence = this.mTable.getCustomizer().getSequenceIdGenerators().contains(scheme);
- if (!isSequence) {
- sequenceNameField.setText("");
- sequenceNameField.setEnabled(false);
- mTable.setSequence(null);
- sequenceNameNoteLabel.setEnabled(false);
- } else {
- sequenceNameField.setEnabled(true);
- sequenceNameNoteLabel.setForeground( NOTE_LABEL_COLOR );
- sequenceNameNoteLabel.setEnabled(true);
- if ( sequenceNameField.getText().length()==0 ) {
- String newMessage = "Please specify a sequence name";
- this.wizardPage.setMessage(newMessage);
- this.wizardPage.setPageComplete(true);
- } else {
- this.wizardPage.setErrorMessage(null);
- this.wizardPage.setPageComplete(true);
- }
- }
- }
-
- class EntityAccessFetchListener implements SelectionListener{
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if (!isUpdatingControls) {
- Button radioBtn = (Button)e.getSource();
- mTable.setAccess( radioBtn.getData().toString() );
- }
- }
- }
-
- private void createEntityAccessControls(Composite composite, int columns) {
- SWTUtil.createLabel(composite, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_access );
-
- Composite parent = new Composite( composite, SWT.NONE);
- SWTUtil.fillColumns( parent , 3);
- parent.setLayout(new RowLayout());
-
- entityAccessField = new Button( parent, SWT.RADIO );
- entityAccessField.setText( "&Field" ); //$NON-NLS1$
- entityAccessField.setData( ORMGenTable.FIELD_ACCESS);
-
- entityAccessProperty = new Button( parent, SWT.RADIO );
- entityAccessProperty.setText( "&Property" );//$NON-NLS1$
- entityAccessProperty.setData( ORMGenTable.PROPERTY_ACCESS );
-
- EntityAccessFetchListener entityAccessFetchListener = new EntityAccessFetchListener();
- entityAccessField.addSelectionListener( entityAccessFetchListener );
- entityAccessProperty.addSelectionListener( entityAccessFetchListener );
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java
deleted file mode 100644
index b53a528370..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
-import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.gen.internal.ORMGenColumn;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.gen.internal.ORMGenTable;
-import org.eclipse.jpt.gen.internal.util.DTPUtil;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-public class TablesAndColumnsCustomizationWizardPage extends NewTypeWizardPage {
-
- private JpaProject jpaProject;
-
- private TreeViewer tableColumnTreeViewer;
-
- private Composite detailPanel ;
- private StackLayout detailPanelStatckLayout;
- private Composite tableGenDetatilGroup;
- private ColumnGenPanel columnGenPanel;
- private Composite columnGenDetatilGroup;
- private TableGenPanel tableGenPanel;
- private ORMGenTable selectedTable;
-
- private ORMGenCustomizer customizer;
-
- protected TablesAndColumnsCustomizationWizardPage(JpaProject jpaProject ) {
- super(true, "TablesAndColumnsCustomizationWizardPage"); //$NON-NLS-1$
- this.jpaProject = jpaProject;
- setTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_tablesAndColumnsPage_title );
- setMessage( JptUiEntityGenMessages.GenerateEntitiesWizard_tablesAndColumnsPage_desc);
- }
-
- // -------- Initialization ---------
- /**
- * The wizard owning this page is responsible for calling this method with the
- * current selection. The selection is used to initialize the fields of the wizard
- * page.
- *
- * @param selection used to initialize the fields
- */
- void init(IStructuredSelection selection) {
- if ( jpaProject != null ) {
- IJavaElement jelem = this.jpaProject.getJavaProject();
- initContainerPage(jelem);
- initTypePage(jelem);
- }
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 1 ;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_CUSTOMIZE_INDIVIDUAL_ENTITIES);
-
- createTableAndColumnsListPanel(composite, 1);
-
- SWTUtil.createLabel( composite, 1, ""); //$NON-NLS-1$
-
- SWTUtil.createSeparator(composite, 1);
-
- createGenerateDetailGroup(composite, 1);
-
- setControl(composite);
- this.setPageComplete( true );
- }
-
- /**
- * A panel with JFace TreeViewer showing tables and columns to be generated into JPA entities
- *
- * @param parent
- * @param columns
- */
- private void createTableAndColumnsListPanel(Composite parent, int columns) {
- Label label = new Label(parent, columns );
- label.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_tablesAndColumnsPage_labelTableAndColumns );
- SWTUtil.fillColumns( label , columns);
-
- GridData data = new GridData();
- data.horizontalSpan = columns;
- data.verticalAlignment = SWT.FILL;
- data.horizontalAlignment = SWT.FILL;
- data.grabExcessHorizontalSpace = true;
- data.heightHint = 200;
- data.grabExcessVerticalSpace = true;
-
- tableColumnTreeViewer = new TreeViewer(parent);
- tableColumnTreeViewer.getTree().setLayoutData( data);
- tableColumnTreeViewer.setContentProvider(new TableColumnTreeContentProvider());
- tableColumnTreeViewer.setLabelProvider(new TableColumnTreeLabelProvider());
-
- tableColumnTreeViewer.addSelectionChangedListener( new ISelectionChangedListener(){
- public void selectionChanged(SelectionChangedEvent event) {
- updateDetailPanel(event.getSelection());
- }
-
- });
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if(visible){
- ORMGenCustomizer customizer = getCustomizer();
- //If user changed the connection or schema
- if( this.customizer != customizer ){
- this.customizer = customizer;
- tableColumnTreeViewer.setInput( customizer );
- }else{
- tableColumnTreeViewer.refresh();
- }
- List<String> tableNames = this.customizer.getTableNames();
-
- //Select the first table
- ORMGenTable ormGenTable = this.customizer.getTable(tableNames.get(0));
- updateTabelGenDetail( ormGenTable );
- }
- }
-
-
- private void updateDetailPanel(ISelection selection) {
- TreeSelection ts = (TreeSelection)selection;
- Object selectedObject = ts.getFirstElement();
- if( selectedObject instanceof ORMGenTable ){
- updateTabelGenDetail( (ORMGenTable)selectedObject );
- }else if( selectedObject instanceof ORMGenColumn ){
- updateColumnGenDetail( (ORMGenColumn)selectedObject );
- }
- }
-
- private void updateColumnGenDetail(ORMGenColumn column) {
- if(columnGenDetatilGroup==null){
- columnGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 4;
- columnGenDetatilGroup.setLayout(gridLayout);
- this.columnGenPanel = new ColumnGenPanel(columnGenDetatilGroup, 4, getCustomizer() , this );
- }
- columnGenPanel.setColumn(column);
- this.detailPanelStatckLayout.topControl = columnGenDetatilGroup;
- this.detailPanel.layout();
- detailPanel.getParent().layout();
- }
-
- private void updateTabelGenDetail(ORMGenTable table) {
- this.selectedTable = table;
- if(tableGenDetatilGroup==null){
- tableGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 4;
- tableGenDetatilGroup.setLayout(gridLayout);
-
- this.tableGenPanel = new TableGenPanel(tableGenDetatilGroup, 4 , false, this );
- createDomainJavaClassesPropertiesGroup(tableGenDetatilGroup, 4 );
- }
- tableGenPanel.setORMGenTable(table);
-
- this.detailPanelStatckLayout.topControl = tableGenDetatilGroup;
- this.detailPanel.layout();
-
- String baseClass = table.getExtends();
- if( baseClass!= null )
- setSuperClass(baseClass, true);
-
- setSuperInterfaces( table.getImplements(), true);
-
- detailPanel.getParent().layout();
- }
-
- protected void createDomainJavaClassesPropertiesGroup(Composite composite, int columns) {
- Group parent = new Group( composite, SWT.NONE);
- parent.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_domainJavaClass );
- parent.setLayout(new GridLayout(columns, false));
- SWTUtil.fillColumns( parent, columns);
-
- createSuperClassControls(parent, columns);
- createSuperInterfacesControls(parent, columns);
-
- //Resize supper class text width to fill the parent group.
- //Have to do it indirectly since fSuperClassDialogField is private in super class.
- Control[] controls = parent.getChildren();
- if( controls.length>1 && controls[1] instanceof Text ){
- Text text = (Text)(parent.getChildren()[1]);
- LayoutUtil.setWidthHint(text, getMaxFieldWidth());
- LayoutUtil.setHorizontalGrabbing(text);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#superClassChanged()
- */
- @Override
- protected IStatus superClassChanged() {
- IStatus status = super.superClassChanged();
- String baseClass = getSuperClass();
- if(baseClass!=null && this.selectedTable!=null ){
- String oldBaseClass = this.selectedTable.getExtends();
- if( !oldBaseClass.equals(baseClass ))
- this.selectedTable.setExtends(baseClass);
- }
- return status;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#addSuperInterface(java.lang.String)
- */
- @Override
- @SuppressWarnings("unchecked")
- public boolean addSuperInterface(String superInterface) {
- super.addSuperInterface(superInterface);
- List interfaces = getSuperInterfaces();
- if(this.selectedTable!=null)
- this.selectedTable.setImplements(interfaces);
- return true;
- }
-
- @Override
- protected void handleFieldChanged(String fieldName) {
- super.handleFieldChanged(fieldName);
- if( this.fSuperClassStatus.matches(IStatus.ERROR)){
- updateStatus(fSuperClassStatus);
- }else{
- setMessage("", IMessageProvider.NONE);
- setErrorMessage(null);
- }
-
- }
-
- private ORMGenCustomizer getCustomizer(){
- GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard();
- return wizard.getCustomizer();
- }
- /**
- * Content provider, and label provider for the DB Table/Column TreeViewer
- *
- */
- class TableColumnTreeContentProvider implements ITreeContentProvider {
- public Object[] getElements(Object inputElement) {
- if( inputElement instanceof ORMGenCustomizer ){
- ORMGenCustomizer input = (ORMGenCustomizer )inputElement;
- List<String> tableNameList = input.getGenTableNames();
- List<ORMGenTable> ret = new ArrayList<ORMGenTable>();
- for(String t : tableNameList){
- ORMGenTable ormGenTable = getCustomizer().getTable( t );
- ret.add( ormGenTable );
- }
- return ret.toArray();
- }
- return new Object[]{};
- }
- public Object[] getChildren(Object parentElement) {
- if( parentElement instanceof ORMGenTable ){
- ORMGenTable table = (ORMGenTable) parentElement;
- List<ORMGenColumn> columns = table.getColumns();
- List<ORMGenColumn> ret = new ArrayList<ORMGenColumn>();
- boolean isCompositePk = table.getDbTable().primaryKeyColumnsSize()>1;
- for( ORMGenColumn col : columns){
- if( col.isForeignKey() )
- continue;
- if( col.isPrimaryKey() ){
- if( isCompositePk ){
- continue;
- }else{
- ret.add(0,col );
- }
- }else{
- ret.add(col);
- }
- }
- return ret.toArray();
- }
- return new Object[]{};
- }
- public Object getParent(Object element) {
- if( element instanceof ORMGenColumn){
- return null;
- }
- return null;
- }
- public boolean hasChildren(Object element) {
- return( element instanceof ORMGenTable );
- }
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
- public void dispose() {}
- }
-
- class TableColumnTreeLabelProvider extends LabelProvider{
-
- @Override
- public Image getImage(Object element) {
- if( element instanceof ORMGenTable ){
- return ImageRepository.getTableImage();
- }else if( element instanceof ORMGenColumn ){
- ORMGenColumn col = ( ORMGenColumn)element;
- return col.isPrimaryKey() ?
- ImageRepository.getKeyColumnImage() :
- ImageRepository.getColumnImage();
- }
- return null;
- }
-
-
- @Override
- public String getText(Object element) {
- if( element instanceof ORMGenTable ){
- return ((ORMGenTable)element).getName();
- }else if( element instanceof ORMGenColumn ){
- return ((ORMGenColumn)element).getName();
- }
- return super.getText(element);
- }
- }
-
- private void createGenerateDetailGroup(Composite parent, int columns) {
- detailPanel = new Composite(parent, SWT.NONE);
- SWTUtil.fillColumns( detailPanel, columns);
-
- detailPanelStatckLayout = new StackLayout();
- detailPanel.setLayout(detailPanelStatckLayout);
-
- Composite emptyPanel = new Composite(detailPanel, SWT.NONE);
- emptyPanel.setLayoutData(new GridData());
-
- detailPanelStatckLayout.topControl = emptyPanel;
- detailPanel.layout();
- }
-
- @Override
- public final void performHelp()
- {
- this.getHelpSystem().displayHelp( GenerateEntitiesFromSchemaWizard.HELP_CONTEXT_ID );
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java
deleted file mode 100644
index 45241827a7..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java
+++ /dev/null
@@ -1,543 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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 - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.jpt.ui.internal.wizards.gen;
-
-import java.lang.reflect.InvocationTargetException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.JptDbPlugin;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.db.Table;
-import org.eclipse.jpt.gen.internal.ORMGenCustomizer;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.ImageRepository;
-import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.ui.internal.util.TableLayoutComposite;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
-
-class TablesSelectorWizardPage extends WizardPage{
-
- private static final int TABLE_COLUMN_INDEX = 0;
- private JpaProject jpaProject;
- private Schema schema = null;
- private ORMGenCustomizer customizer = null;
- private boolean synchronizePersistenceXml = true;
-
- private DatabaseGroup databaseGroup;
- private CheckboxTableViewer tableTable;
-
- TablesSelectorWizardPage(JpaProject jpaProject ) {
- super("TablesSelectorWizardPage"); //$NON-NLS-1$
- this.jpaProject = jpaProject;
- this.schema = jpaProject.getDefaultDbSchema();
- setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_selectTable );
- setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_chooseEntityTable );
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- doStatusUpdate();
- }
-
- // -------- Provide access to wrapped DTP connection related classes ---------
- ConnectionProfile getProjectConnectionProfile() {
- String profileName = this.jpaProject.getDataSource().getConnectionProfileName();
- return this.connectionProfileNamed(profileName);
- }
-
- ConnectionProfile connectionProfileNamed(String profileName) {
- return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(profileName);
- }
-
- Schema getSchema(){
- return this.schema;
- }
-
- void setSchema(Schema s){
- this.schema = s;
- }
-
- private Collection<Table> possibleTables() {
- Schema schema = this.getSchema();
- if (schema != null && schema.getName() != null) {
- return CollectionTools.collection(schema.tables());
- }
- return Collections.<Table> emptyList();
- }
-
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
-
- Composite composite = new Composite(parent, SWT.NULL);
- int nColumns= 3;
- GridLayout layout = new GridLayout();
- layout.numColumns = nColumns;
- composite.setLayout(layout);
- this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_SELECT_TABLES);
-
- this.databaseGroup = createDatabaseGroup(composite, 400);
-
- createTablesSelectionControl(composite, nColumns);
-
- //Filler column
- new Label( composite, SWT.NONE);
-
- final Button synchronizeClassesCheckBox = new Button(composite, SWT.CHECK);
- synchronizeClassesCheckBox.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_synchronizeClasses );
- synchronizeClassesCheckBox.setSelection(true);
- synchronizeClassesCheckBox.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- setSynchronizePersistenceXml(synchronizeClassesCheckBox.getSelection());
- }
-
- });
- fillColumns( synchronizeClassesCheckBox, 2);
-
-
- //Filler column
- new Label( composite, SWT.NONE);
- //Restore default button
- final Button restoreBtn = new Button(composite, SWT.PUSH );
- restoreBtn.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_Restore_Defaults );
- restoreBtn.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
- public void widgetSelected(SelectionEvent e) {
- if( customizer!=null && customizer.getFile()!=null ){
- if( customizer.getFile().exists() ){
- customizer.getFile().delete();
- }
- updateTablesSelector( databaseGroup.getSelectedSchema() );
- deselectAllTables();
- }
- }
-
- });
- GridData gridData = new GridData();
- gridData.horizontalAlignment = SWT.END;
- restoreBtn.setLayoutData(gridData);
-
-
- this.getHelpSystem().setHelp(this.tableTable.getControl(), JpaHelpContextIds.DIALOG_GENERATE_ENTITIES_TABLES);
-
- this.setControl(composite);
-
- this.setPageComplete(true);
- }
-
- @Override
- public void dispose() {
- if (this.databaseGroup != null)
- this.databaseGroup.dispose();
- super.dispose();
- }
-
- @Override
- public IWizardPage getPreviousPage() {
- IWizardPage prevPage = super.getPreviousPage();
- if (prevPage instanceof PromptJPAProjectWizardPage)
- //Prevent going back to the PromptJPAProjectWizardPage
- //if JPA project already selected
- return prevPage.getPreviousPage();
- else
- return prevPage;
- }
-
- private DatabaseGroup createDatabaseGroup(Composite parent, int widthHint) {
- DatabaseGroup dbGroup = new DatabaseGroup(this.getContainer(), jpaProject, parent, widthHint);
- /**
- * listen for when the Database Connection changes its selected schema
- * so we can keep the page in synch
- */
- class DatabasePageListener implements DatabaseGroup.Listener {
- public void selectedConnectionProfileChanged(ConnectionProfile connectionProfile) {
- jpaProject.getDataSource().setConnectionProfileName(connectionProfile.getName());
- }
- @SuppressWarnings("unchecked")
- public void selectedSchemaChanged(Schema schema) {
- if (schema==null) {
- updateTablesListViewer(Collections.EMPTY_LIST );
- } else {
- // store the *identifier* in the JPA project, since it gets put in Java annotations
- jpaProject.setUserOverrideDefaultSchema(schema.getIdentifier());
- setSchema( schema );
- updateTablesSelector(schema);
- }
- doStatusUpdate();
- }
- }
- dbGroup.addListener(new DatabasePageListener());
- dbGroup.init();
- return dbGroup;
- }
-
- boolean synchronizePersistenceXml() {
- return this.synchronizePersistenceXml;
- }
-
- private void setSynchronizePersistenceXml(boolean synchronizePersistenceXml){
- this.synchronizePersistenceXml = synchronizePersistenceXml;
- }
-
- private void selectAllTables(){
- this.tableTable.setAllChecked(true);
- doStatusUpdate();
- }
-
- private void deselectAllTables(){
- this.tableTable.setAllChecked(false);
- doStatusUpdate();
- }
-
- private void initTablesSelectionControl(Collection<Table> possibleTables) {
- this.tableTable.setInput(possibleTables);
- }
-
- private void createTablesSelectionControl(Composite parent, int columns) {
- Label tableLabel = new Label(parent, SWT.NONE);
- GridData gd= new GridData();
- gd.horizontalAlignment = GridData.FILL;
- gd.verticalAlignment = GridData.BEGINNING;
- tableLabel.setLayoutData( gd );
- tableLabel.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tables );
-
- TableLayoutComposite layout= new TableLayoutComposite(parent, SWT.NONE);
- addColumnLayoutData(layout);
-
- final org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(layout, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK);
-
- TableColumn tableNameColumn = new TableColumn(table, SWT.NONE, TABLE_COLUMN_INDEX);
- tableNameColumn.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tableColumn );
- tableNameColumn.setResizable(true);
-
- gd= new GridData(GridData.FILL_BOTH);
- gd.heightHint= SWTUtil.getTableHeightHint(table, 20);
- gd.widthHint = 250;
- gd.grabExcessHorizontalSpace = true;
- gd.grabExcessVerticalSpace = true ;
- layout.setLayoutData(gd);
- layout.setBackground(new Color( Display.getDefault(), 255, 0,0));
-
- this.tableTable = new CheckboxTableViewer(table);
- this.tableTable.setUseHashlookup(true);
- this.tableTable.setLabelProvider(this.buildTableTableLabelProvider());
- this.tableTable.setContentProvider(this.buildTableTableContentProvider());
- this.tableTable.setSorter(new ViewerSorter() {
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- return ((Table) e1).getName().compareTo(((Table) e2).getName());
- }
- });
-
- this.tableTable.addPostSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- handleTablesListSelectionChanged(event);
- }
- });
-
- table.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.keyCode == SWT.F2 && e.stateMask == SWT.NONE) {
- editEntityNameIfPossible();
- e.doit= false;
- }
- }
- });
-
- updateTablesSelector( databaseGroup.getSelectedSchema() );
- createButtonComposite(parent);
- initTablesSelectionControl(possibleTables());
- }
-
- private void createButtonComposite(Composite parent){
-
- Composite buttonComposite = new Composite(parent, SWT.NULL);
- GridLayout buttonLayout = new GridLayout(1, false);
- buttonComposite.setLayout(buttonLayout);
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- buttonComposite.setLayoutData(data);
-
- Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
- selectAllButton.setToolTipText(JptUiMessages.General_selectAll);
- selectAllButton.setImage( ImageRepository.getSelectAllButtonImage() );
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- selectAllButton.setLayoutData(gridData);
- selectAllButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- selectAllTables();
- }
- });
-
- Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
- deselectAllButton.setToolTipText(JptUiMessages.General_deselectAll);
- deselectAllButton.setImage( ImageRepository.getDeselectAllButtonImage() );
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- deselectAllButton.setLayoutData(gridData);
- deselectAllButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
- deselectAllTables();
- }
- });
- }
-
-
- private void addColumnLayoutData(TableLayoutComposite layout) {
- layout.addColumnData(new ColumnWeightData(50, true));
- }
-
- void editEntityNameIfPossible(){
- Object[] selected = ((IStructuredSelection) this.tableTable.getSelection()).toArray();
- if (selected.length != 1) {
- return;
- }
- }
-
- void handleTablesListSelectionChanged(SelectionChangedEvent event) {
- doStatusUpdate();
- }
-
- private IBaseLabelProvider buildTableTableLabelProvider() {
- return new TableTableLabelProvider();
- }
-
- private IContentProvider buildTableTableContentProvider() {
- return new TableTableContentProvider();
- }
-
- public Schema getDefaultSchema() {
- return this.jpaProject.getDefaultDbSchema() ;
- }
-
- Collection<Table> getSelectedTables() {
- ArrayList<Table> selectedTables = new ArrayList<Table>();
- for (Object selectedTable : this.tableTable.getCheckedElements())
- selectedTables.add((Table) selectedTable);
- return selectedTables;
- }
-
- private boolean hasTablesSelected() {
- return (this.tableTable != null) ? (this.getSelectedTables().size() > 0) : false;
- }
-
- void updateTablesListViewer(Collection<Table> possibleTables) {
- if (this.tableTable != null) {
- this.initTablesSelectionControl(possibleTables);
- }
- }
-
- /**
- * Update the status line and the OK button according to the given status
- */
- protected void doStatusUpdate() {
- if ( ! this.hasTablesSelected()) {
- this.setPageComplete(false);
- }else{
- setPageComplete(true);
- try{
- getContainer().run(false, false, new IRunnableWithProgress(){
- public void run( final IProgressMonitor monitor )
- throws InvocationTargetException, InterruptedException
- {
- monitor.beginTask("Updating", 10);
-
- Collection<Table> ret = getSelectedTables();
- ArrayList<String> tableNames = new ArrayList<String>();
- for( Table t : ret ){
- tableNames.add(t.getName());
- }
- Schema schema = getSchema();
- if( schema == null ){
- return ;
- }
- customizer.setSchema(schema);
- customizer.setTableNames(tableNames);
- monitor.done();
- }
- });
- } catch (Exception e) {
- JptUiPlugin.log(e);
- }
-
- }
- }
-
- // ********** inner classes **********
- private class TableTableLabelProvider extends LabelProvider implements ITableLabelProvider {
-
- TableTableLabelProvider() {
- super();
- }
-
- @Override
- public String getText(Object element) {
- return ((Table) element).getName();
- }
-
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (element == null) {
- return null;
- }
- switch (columnIndex) {
- case TABLE_COLUMN_INDEX:
- return ((Table) element).getName();
-
- }
- throw new IllegalArgumentException("invalid column index: " + columnIndex);// $NON-NLS-1$
- }
-
- }
-
-
- private class TableTableContentProvider implements IStructuredContentProvider {
-
- TableTableContentProvider() {
- super();
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
-
- public void dispose() {}
-
- public Object[] getElements(Object inputElement) {
- return ((Collection<?>) inputElement).toArray();
- }
-
- }
-
- private void updateTablesSelector(final Schema schema) {
- if(schema ==null)
- return;
- this.jpaProject.setUserOverrideDefaultSchema( schema.getIdentifier());
-
- updateTablesListViewer(CollectionTools.collection(schema.tables()));
-
- //Create the ORMGenCustomizer
- GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) getWizard();
- customizer = wizard.createORMGenCustomizer( schema );
-
- if( tableTable!=null && customizer != null ){
- restoreWizardState();
- }
- doStatusUpdate();
-
- }
-
- private boolean restoreWizardState(){
- boolean pageComplete = false;
- List<String> preSelectedTableNames = this.customizer.getTableNames();
- if(preSelectedTableNames!=null && preSelectedTableNames.size()>0) {
- Set<String> set = new HashSet<String>();
- for(String s : preSelectedTableNames ){
- set.add(s);
- }
- TableItem[] items = this.tableTable.getTable().getItems();
- for (int i = 0; i < items.length; ++i) {
- TableItem item = items[i];
- org.eclipse.jpt.db.Table element = (org.eclipse.jpt.db.Table)item.getData();
- if (element != null) {
- boolean check = set.contains(element.getName());
- // only set if different, to avoid flicker
- if (item.getChecked() != check) {
- item.setChecked(check);
- pageComplete = true;
- }
- }
- }
- }
- return pageComplete;
- }
-
-
- /**
- * Set the layoutData of the input control to occupy specified number of columns
- * @param c
- * @param columns
- */
- private void fillColumns(Control c, int columns){
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = columns;
- layoutData.verticalAlignment = SWT.FILL;
- layoutData.horizontalAlignment = SWT.FILL;
- layoutData.grabExcessHorizontalSpace = true;
- layoutData.grabExcessVerticalSpace = false;
- c.setLayoutData(layoutData);
- return ;
- }
-
- @Override
- public final void performHelp()
- {
- this.getHelpSystem().displayHelp( GenerateEntitiesFromSchemaWizard.HELP_CONTEXT_ID );
- }
-
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java
deleted file mode 100644
index 344f3a64e1..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle.
- * 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 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.orm;
-
-import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.context.JpaContextNode;
-import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties;
-import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JptUiIcons;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
-import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
-
-public class MappingFileWizard extends DataModelWizard
- implements INewWizard
-{
- private MappingFileWizardPage page;
-
-
- public MappingFileWizard() {
- this(null);
- }
-
- public MappingFileWizard(IDataModel dataModel) {
- super(dataModel);
- setWindowTitle(JptUiMessages.MappingFileWizard_title);
- setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_FILE_WIZ_BANNER));
- }
-
-
- @Override
- protected void doAddPages() {
- super.doAddPages();
- page = buildMappingFileWizardPage();
- addPage(page);
- }
-
- protected MappingFileWizardPage buildMappingFileWizardPage() {
- return new MappingFileWizardPage(getDataModel(), "Page_1");
- }
-
- @Override
- protected IDataModelProvider getDefaultProvider() {
- return new OrmFileCreationDataModelProvider();
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- // check for project, source folder, persistence unit?
- if (selection == null || selection.isEmpty()) {
- return;
- }
-
- Object firstSelection = selection.getFirstElement();
-
- PersistenceUnit pUnit = extractPersistenceUnit(firstSelection);
- IFolder sourceFolder = extractSourceFolder(pUnit, firstSelection);
- IProject project = extractProject(pUnit, sourceFolder, firstSelection);
-
- if (project != null) {
- getDataModel().setStringProperty(OrmFileCreationDataModelProperties.PROJECT_NAME, project.getName());
- }
- if (sourceFolder != null) {
- getDataModel().setStringProperty(OrmFileCreationDataModelProperties.SOURCE_FOLDER, sourceFolder.getFullPath().toPortableString());
- }
- if (pUnit != null) {
- getDataModel().setBooleanProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, true);
- getDataModel().setStringProperty(OrmFileCreationDataModelProperties.PERSISTENCE_UNIT, pUnit.getName());
- }
- }
-
- private PersistenceUnit extractPersistenceUnit(Object selection) {
- if (selection instanceof PersistenceUnit) {
- return (PersistenceUnit) selection;
- }
- PersistenceUnit pUnit = null;
- if (selection instanceof JpaContextNode) {
- try {
- pUnit = ((JpaContextNode) selection).getPersistenceUnit();
- }
- catch (Exception e) { /* do nothing, just continue */ }
- }
- if (pUnit == null && selection instanceof IAdaptable) {
- pUnit = (PersistenceUnit) ((IAdaptable) selection).getAdapter(PersistenceUnit.class);
-
- }
- return pUnit;
- }
-
- private IFolder extractSourceFolder(PersistenceUnit pUnit, Object selection) {
- IJavaProject javaProject = null;
- IFolder srcFolder = null;
- if (pUnit != null) {
- javaProject = pUnit.getJpaProject().getJavaProject();
- srcFolder = findSourceFolder(javaProject, pUnit.getResource());
- if (srcFolder != null) {
- return srcFolder;
- }
-
- }
- if (selection instanceof IResource) {
- javaProject = JavaCore.create(((IResource) selection).getProject());
- if (javaProject.exists()) {
- srcFolder = findSourceFolder(javaProject, (IResource) selection);
- if (srcFolder != null) {
- return srcFolder;
- }
- }
- }
-
- if (selection instanceof IAdaptable) {
- IResource resource = (IResource) ((IAdaptable) selection).getAdapter(IResource.class);
- if (resource != null) {
- javaProject = JavaCore.create((resource).getProject());
- if (javaProject.exists()) {
- srcFolder = findSourceFolder(javaProject, resource);
- if (srcFolder != null) {
- return srcFolder;
- }
- }
- }
- }
- return null;
- }
-
- private IFolder findSourceFolder(IJavaProject javaProject, IResource resource) {
- if (JptCorePlugin.getJpaProject(javaProject.getProject()) == null) {
- // not even a jpa project
- return null;
- }
- while (resource != null && ! (resource instanceof IFolder)) {
- resource = resource.getParent();
- }
- if (resource == null) {
- return null;
- }
- IFolder folder = (IFolder) resource;
- try {
- IPackageFragmentRoot packageFragmentRoot = null;
- while (packageFragmentRoot == null && folder != null) {
- packageFragmentRoot = javaProject.findPackageFragmentRoot(folder.getFullPath());
- if (packageFragmentRoot == null) {
- IPackageFragment packageFragment = javaProject.findPackageFragment(folder.getFullPath());
- if (packageFragment != null) {
- packageFragmentRoot = (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
- }
- }
- if (packageFragmentRoot == null) {
- try {
- folder = (IFolder) folder.getParent();
- }
- catch (ClassCastException cce) {
- folder = null;
- }
- }
- }
- if (packageFragmentRoot == null) {
- return null;
- }
- if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
- return (IFolder) packageFragmentRoot.getResource();
- }
- }
- catch (JavaModelException jme) { /* do nothing, return null */ }
- return null;
- }
-
- private IProject extractProject(PersistenceUnit pUnit, IFolder sourceFolder, Object selection) {
- if (pUnit != null) {
- return pUnit.getJpaProject().getProject();
- }
- if (sourceFolder != null) {
- return sourceFolder.getProject();
- }
-
- IProject project = null;
- if (selection instanceof IResource) {
- project = ((IResource) selection).getProject();
- }
- if (project == null && selection instanceof IJavaElement) {
- project = ((IJavaElement) selection).getJavaProject().getProject();
- }
- if (project == null && selection instanceof JpaContextNode) {
- project = ((JpaContextNode) selection).getJpaProject().getProject();
- }
- if (project == null && selection instanceof IAdaptable) {
- project = (IProject) ((IAdaptable) selection).getAdapter(IProject.class);
- if (project == null) {
- IResource resource = (IResource) ((IAdaptable) selection).getAdapter(IResource.class);
- if (resource != null) {
- project = resource.getProject();
- }
- }
- if (project == null) {
- IJavaElement javaElement = (IJavaElement) ((IAdaptable) selection).getAdapter(IJavaElement.class);
- if (javaElement != null) {
- project = javaElement.getJavaProject().getProject();
- }
- }
- }
-
- if (project != null && JptCorePlugin.getJpaProject(project) != null) {
- return project;
- }
-
- return null;
- }
-
- protected void postPerformFinish() throws InvocationTargetException {
- try {
- String projectName = (String) getDataModel().getProperty(OrmFileCreationDataModelProperties.PROJECT_NAME);
- IProject project = ProjectUtilities.getProject(projectName);
- String sourceFolder = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.SOURCE_FOLDER);
- String filePath = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.FILE_PATH);
-
- IFile file = project.getWorkspace().getRoot().getFile(new Path(sourceFolder).append(filePath));
- openEditor(file);
- }
- catch (Exception cantOpen) {
- throw new InvocationTargetException(cantOpen);
- }
- }
-
- private void openEditor(final IFile file) {
- if (file != null) {
- getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IDE.openEditor(page, file, true);
- }
- catch (PartInitException e) {
- JptUiPlugin.log(e);
- }
- }
- });
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java
deleted file mode 100644
index b98f89aa3b..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle.
- * 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 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.ui.internal.wizards.orm;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties;
-import org.eclipse.jpt.ui.JptUiPlugin;
-import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-import org.eclipse.ui.dialogs.ISelectionStatusValidator;
-import org.eclipse.ui.model.WorkbenchContentProvider;
-import org.eclipse.ui.model.WorkbenchLabelProvider;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
-
-public class MappingFileWizardPage extends DataModelWizardPage
- implements OrmFileCreationDataModelProperties
-{
- private Label projectNameLabel;
-
- private Combo projectNameCombo;
-
- private Label sourceFolderLabel;
-
- private Text sourceFolderText;
-
- private Label filePathLabel;
-
- private Text filePathText;
-
- private Label accessLabel;
-
- private Combo accessCombo;
-
- private Button addToPersistenceUnitButton;
-
- private Label persistenceUnitLabel;
-
- private Combo persistenceUnitCombo;
-
-
- public MappingFileWizardPage(IDataModel dataModel, String pageName) {
- super(dataModel, pageName);
- setTitle(JptUiMessages.MappingFileWizardPage_title);
- setDescription(JptUiMessages.MappingFileWizardPage_desc);
- setPageComplete(false);
- }
-
-
- @Override
- protected String[] getValidationPropertyNames() {
- return new String[] {
- PROJECT_NAME,
- SOURCE_FOLDER,
- FILE_PATH,
- DEFAULT_ACCESS,
- ADD_TO_PERSISTENCE_UNIT,
- PERSISTENCE_UNIT
- };
- }
-
- @Override
- protected Composite createTopLevelComposite(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- layout.numColumns = 3;
- composite.setLayout(layout);
- GridData data = new GridData();
- data.verticalAlignment = GridData.FILL;
- data.horizontalAlignment = GridData.FILL;
- data.widthHint = 300;
- composite.setLayoutData(data);
-
- this.projectNameLabel = new Label(composite, SWT.NONE);
- this.projectNameLabel.setText(JptUiMessages.MappingFileWizardPage_projectLabel);
- data = new GridData();
- this.projectNameLabel.setLayoutData(data);
-
- this.projectNameCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = 300;
- data.horizontalSpan = 1;
- this.projectNameCombo.setLayoutData(data);
- this.synchHelper.synchCombo(this.projectNameCombo, PROJECT_NAME, null);
- new Label(composite, SWT.NONE);
-
- this.sourceFolderLabel = new Label(composite, SWT.NONE);
- this.sourceFolderLabel.setText(JptUiMessages.MappingFileWizardPage_sourceFolderLabel);
- data = new GridData();
- this.sourceFolderLabel.setLayoutData(data);
-
- this.sourceFolderText = new Text(composite, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = 300;
- data.horizontalSpan = 1;
- this.sourceFolderText.setLayoutData(data);
- this.synchHelper.synchText(this.sourceFolderText, SOURCE_FOLDER, null);
-
- Button sourceFolderButton = new Button(composite, SWT.PUSH);
- sourceFolderButton.setText(JptUiMessages.General_browse);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 1;
- sourceFolderButton.addSelectionListener(
- new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
- handleSourceFolderButtonPressed();
- }
- });
-
- this.filePathLabel = new Label(composite, SWT.NONE);
- this.filePathLabel.setText(JptUiMessages.MappingFileWizardPage_filePathLabel);
- data = new GridData();
- this.filePathLabel.setLayoutData(data);
-
- this.filePathText = new Text(composite, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = 300;
- data.horizontalSpan = 1;
- this.filePathText.setLayoutData(data);
- this.synchHelper.synchText(this.filePathText, FILE_PATH, null);
- new Label(composite, SWT.NONE);
-
- this.accessLabel = new Label(composite, SWT.NONE);
- this.accessLabel.setText(JptUiMessages.MappingFileWizardPage_accessLabel);
- data = new GridData();
- this.accessLabel.setLayoutData(data);
-
- this.accessCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = 300;
- data.horizontalSpan = 1;
- this.accessCombo.setLayoutData(data);
- this.synchHelper.synchCombo(this.accessCombo, DEFAULT_ACCESS, null);
- new Label(composite, SWT.NONE);
-
- this.addToPersistenceUnitButton = new Button(composite, SWT.CHECK | SWT.BEGINNING);
- this.addToPersistenceUnitButton.setText(JptUiMessages.MappingFileWizardPage_addToPersistenceUnitButton);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 3;
- this.addToPersistenceUnitButton.setLayoutData(data);
- this.synchHelper.synchCheckbox(this.addToPersistenceUnitButton, ADD_TO_PERSISTENCE_UNIT, null);
-
- this.persistenceUnitLabel = new Label(composite, SWT.NONE);
- this.persistenceUnitLabel.setText(JptUiMessages.MappingFileWizardPage_persistenceUnitLabel);
- data = new GridData();
- this.persistenceUnitLabel.setLayoutData(data);
-
- this.persistenceUnitCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = 300;
- data.horizontalSpan = 1;
- this.persistenceUnitCombo.setLayoutData(data);
- this.synchHelper.synchCombo(this.persistenceUnitCombo, PERSISTENCE_UNIT, null);
-
- new Label(composite, SWT.NONE);
-
-// classText.setFocus();
- PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, getInfopopID());
- Dialog.applyDialogFont(parent);
- return composite;
- }
-
- private void handleSourceFolderButtonPressed() {
- ISelectionStatusValidator validator = getSourceFolderDialogSelectionValidator();
- ViewerFilter filter = getSourceFolderDialogViewerFilter();
- ITreeContentProvider contentProvider = new WorkbenchContentProvider();
- ILabelProvider labelProvider = new WorkbenchLabelProvider();
- ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
- dialog.setValidator(validator);
- dialog.setTitle(JptUiMessages.MappingFileWizardPage_accessLabel_sourceFolderDialogTitle);
- dialog.setMessage(JptUiMessages.MappingFileWizardPage_accessLabel_sourceFolderDialogDesc);
- dialog.addFilter(filter);
- String projectName = model.getStringProperty(PROJECT_NAME);
- if (projectName==null || projectName.length()==0) {
- return;
- }
- IProject project = ProjectUtilities.getProject(projectName);
- dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
-
- if (project != null) {
- dialog.setInitialSelection(project);
- }
- if (dialog.open() == Window.OK) {
- Object element = dialog.getFirstResult();
- if (element instanceof IContainer) {
- IContainer container = (IContainer) element;
- model.setProperty(SOURCE_FOLDER, container.getFullPath().toPortableString());
- }
- }
- }
-
- private ISelectionStatusValidator getSourceFolderDialogSelectionValidator() {
- return new ISelectionStatusValidator() {
- public IStatus validate(Object[] selection) {
- if (selection != null && selection[0] != null && ! (selection[0] instanceof IProject)) {
- return Status.OK_STATUS;
- }
- return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, JptUiMessages.MappingFileWizardPage_incorrectSourceFolderError);
- }
- };
- }
-
- private ViewerFilter getSourceFolderDialogViewerFilter() {
- return new ViewerFilter() {
- @Override
- public boolean select(Viewer viewer, Object parent, Object element) {
- if (element instanceof IProject) {
- IProject project = (IProject) element;
- return project.getName().equals(model.getProperty(PROJECT_NAME));
- }
- else if (element instanceof IFolder) {
- IFolder folder = (IFolder) element;
- // only show source folders
- IProject project = ProjectUtilities.getProject(model.getStringProperty(PROJECT_NAME));
- IPackageFragmentRoot[] sourceFolders = J2EEProjectUtilities.getSourceContainers(project);
- for (int i = 0; i < sourceFolders.length; i++) {
- if (sourceFolders[i].getResource()!= null && sourceFolders[i].getResource().equals(folder)) {
- return true;
- }
- }
- }
- return false;
- }
- };
- }
-
- void init(IWorkbench workbench, IStructuredSelection selection) {
-
- }
-}

Back to the top