diff options
author | nhauge | 2008-04-03 02:34:25 +0000 |
---|---|---|
committer | nhauge | 2008-04-03 02:34:25 +0000 |
commit | 79b5601c8ed69a88c273c83605912a918c1f2ea4 (patch) | |
tree | 1f7bb3dfb1e94ac4fcaa376632504b616998552f /jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties | |
parent | a21a5fadac61d140764a5bfbb3b44be13ccd1d21 (diff) | |
download | webtools.dali-200804020001.tar.gz webtools.dali-200804020001.tar.xz webtools.dali-200804020001.zip |
This commit was manufactured by cvs2svn to create tag 'v200804020001'.v200804020001
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties')
2 files changed, 0 insertions, 733 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java deleted file mode 100644 index cc0b64d8f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java +++ /dev/null @@ -1,309 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.properties; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PropertyPage; -import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelSynchHelper; -import org.eclipse.wst.common.frameworks.internal.ui.ValidationStatus; - -public abstract class DataModelPropertyPage - extends PropertyPage - implements Listener, IDataModelListener -{ - protected IDataModel model; - - private ValidationStatus status = new ValidationStatus(); - private Map validationMap; - private String[] validationPropertyNames; - private boolean isValidating = false; - - protected DataModelSynchHelper synchHelper; - - private String infopopID; - - - protected DataModelPropertyPage(IDataModel model) { - super(); - this.model = model; - model.addListener(this); - synchHelper = initializeSynchHelper(model); - } - - - /** - * @return - */ - public DataModelSynchHelper initializeSynchHelper(IDataModel dm) { - return new DataModelSynchHelper(dm); - } - - - @Override - protected Control createContents(Composite parent) { - Composite top = createTopLevelComposite(parent); - setupInfopop(top); - setDefaults(); - addListeners(); - initializeValidationProperties(); - return top; - } - - private void initializeValidationProperties() { - validationPropertyNames = getValidationPropertyNames(); - if (validationPropertyNames == null || validationPropertyNames.length == 0) - validationMap = Collections.EMPTY_MAP; - else { - validationMap = new HashMap(validationPropertyNames.length); - for (int i = 0; i < validationPropertyNames.length; i++) - validationMap.put(validationPropertyNames[i], new Integer(i)); - } - } - - /** - * Subclass should return the model property names that need to be validated on this page in the - * order that they should present their messages. - * - * @return - */ - protected abstract String[] getValidationPropertyNames(); - - /** - * Return the top level Composite for this page. - */ - protected abstract Composite createTopLevelComposite(Composite parent); - - /** - * Set up info pop hooks if set. - */ - protected void setupInfopop(Control parent) { - if (getInfopopID() != null) - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, getInfopopID()); - } - - /** - * Setup the default values for this page. Subclasses should override to provide appropriate - * defaults. - */ - protected void setDefaults() { - restoreDefaultSettings(); - } - - /** - * Subclasses should implement this method if they have default settings that have been stored - * and need to be restored. - * - * @see storeDefaultSettings() - */ - protected void restoreDefaultSettings() { - } - - /** - * Add Listeners to controls at this point to avoid unnecessary events. Subclasses should - * override to add listeners to its controls. - */ - protected void addListeners() { - } - - /** - * Exiting the page. Subclasses may extend. - */ - protected void exit() { - } - - protected boolean getStatus(Integer key) { - return status.hasError(key); - } - - /** - * Sent when an event that the receiver has registered for occurs. If a subclass overrides this - * method, it must call super. - * - * @param event - * the event which occurred - */ - public void handleEvent(org.eclipse.swt.widgets.Event event) { - } - - /** - * Set the error message for this page based on the last error in the ValidationStatus. - */ - protected void setErrorMessage() { - String error = status.getLastErrMsg(); - if (error == null) { - if (getErrorMessage() != null) - setErrorMessage((String) null); - String warning = status.getLastWarningMsg(); - if (warning == null) { - if (getMessage() != null && getMessageType() == IMessageProvider.WARNING) - setMessage(null, IMessageProvider.WARNING); - else { - String info = status.getLastInfoMsg(); - if (info == null) { - if (getMessage() != null && getMessageType() == IMessageProvider.INFORMATION) - setMessage(null, IMessageProvider.INFORMATION); - } else if (!info.equals(getMessage())) { - setMessage(info, IMessageProvider.INFORMATION); - } - } - } else if (!warning.equals(getMessage())) - setMessage(warning, IMessageProvider.WARNING); - } else if (!error.equals(getErrorMessage())) - setErrorMessage(error); - } - - protected void setErrorStatus(Integer key, String errorMessage) { - status.setErrorStatus(key, errorMessage); - } - - protected void setWarningStatus(Integer key, String warningMessage) { - status.setWarningStatus(key, warningMessage); - } - - protected void setInfoStatus(Integer key, String infoMessage) { - status.setInfoStatus(key, infoMessage); - } - - protected void setOKStatus(Integer key) { - status.setOKStatus(key); - } - - /** - * This should be called by the Wizard just prior to running the performFinish operation. - * Subclasses should override to store their default settings. - */ - public void storeDefaultSettings() { - } - - /** - * The page is now being validated. At this time, each control is validated and then the - * controls are updated based on the results in the ValidationStatus which was updated during - * <code>validateControls()</code>. Finally, it will display the last error message and it - * will set the page complete. Subclasses will not typically override this method. - */ - protected void validatePage() { - if (!isValidating) { - isValidating = true; - try { - validateControlsBase(); - updateControls(); - setErrorMessage(); - setValid(status.getLastErrMsg() == null); - } - finally { - isValidating = false; - } - } - } - - /** - * Validate individual controls. Use validation keys to keep track of errors. - * - * @see setOKStatus(Integer) and setErrorMessage(Integer, String) - */ - protected final String validateControlsBase() { - if (!validationMap.isEmpty()) { - String propName; - for (int i = 0; i < validationPropertyNames.length; i++) { - propName = validationPropertyNames[i]; - Integer valKey = (Integer) validationMap.get(propName); - if (valKey != null) - validateProperty(propName, valKey); - if (!getStatus(valKey)) - return propName; - } - } - return null; - } - - /** - * @param propertyName - * @param validationkey - */ - private void validateProperty(String propertyName, Integer validationKey) { - setOKStatus(validationKey); - IStatus status1 = model.validateProperty(propertyName); - if (!status1.isOK()) { - String message = status1.isMultiStatus() ? status1.getChildren()[0].getMessage() : status1.getMessage(); - switch (status1.getSeverity()) { - case IStatus.ERROR : - setErrorStatus(validationKey, message); - break; - case IStatus.WARNING : - setWarningStatus(validationKey, message); - break; - case IStatus.INFO : - setInfoStatus(validationKey, message); - break; - } - } - } - - /** - * Update the enablement of controls after validation. Sublcasses should check the status of - * validation keys to determine enablement. - */ - protected void updateControls() { - } - - - /* - * 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) - */ - public void propertyChanged(DataModelEvent event) { - String propertyName = event.getPropertyName(); - if (validationPropertyNames != null && (event.getFlag() == DataModelEvent.VALUE_CHG || (!isValid() && event.getFlag() == DataModelEvent.VALID_VALUES_CHG))) { - for (int i = 0; i < validationPropertyNames.length; i++) { - if (validationPropertyNames[i].equals(propertyName)) { - validatePage(); - break; - } - } - } - } - - /** - * @return Returns the model. - */ - protected IDataModel getDataModel() { - return model; - } - - public void dispose() { - super.dispose(); - if (synchHelper != null) { - synchHelper.dispose(); - synchHelper = null; - } - } - - protected String getInfopopID() { - return infopopID; - } - - public void setInfopopID(String infopopID) { - this.infopopID = infopopID; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java deleted file mode 100644 index 91d7da6310..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java +++ /dev/null @@ -1,424 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.properties; - -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JpaModelManager; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; -import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.ui.internal.DTPUiTools; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -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.Group; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; - -public class JpaProjectPropertiesPage - extends DataModelPropertyPage - implements JpaFacetDataModelProperties -{ - private PlatformGroup platformGroup; - - private ConnectionGroup connectionGroup; - - private PersistentClassManagementGroup persistentClassManagementGroup; - - - /** - * Constructor for SamplePropertyPage. - */ - public JpaProjectPropertiesPage() { - super(DataModelFactory.createDataModel(new JpaFacetDataModelProvider())); - } - - - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - - platformGroup = new PlatformGroup(composite); - connectionGroup = new ConnectionGroup(composite); - persistentClassManagementGroup = new PersistentClassManagementGroup(composite); - - setRuntime(); - - Dialog.applyDialogFont(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE); - - return composite; - } - - private void setRuntime() { - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(getJpaProject().getProject()); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - return; - } - IRuntime runtime = facetedProject.getPrimaryRuntime(); - model.setProperty(JpaFacetDataModelProperties.RUNTIME, runtime); - } - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { - JpaFacetDataModelProperties.PLATFORM_ID, - JpaFacetDataModelProperties.CONNECTION, - JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES - }; - } - - protected JpaProject getJpaProject() { - return (JpaProject) this.getElement().getAdapter(JpaProject.class); - } - - Combo createCombo(Composite container, boolean fillHorizontal) { - Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); - if (fillHorizontal) { - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - else { - combo.setLayoutData(new GridData()); - } - return combo; - } - - 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; - } - - @Override - protected void performDefaults() { - platformGroup.performDefaults(); - connectionGroup.performDefaults(); - persistentClassManagementGroup.performDefaults(); - } - - @Override - public boolean performOk() { - JpaProject jpaProject = this.getJpaProject(); - if (jpaProject == null) { - return true; // the facet has been uninstalled during our trip to the properties - } - - boolean change = false; - boolean platformChange = false; - - IProject project = jpaProject.getProject(); - - String platform = this.model.getStringProperty(JpaFacetDataModelProperties.PLATFORM_ID); - if ( ! platform.equals(jpaProject.getJpaPlatform().getId())) { - change = true; - platformChange = true; - JptCorePlugin.setJpaPlatformId(project, platform); - } - - String connection = this.model.getStringProperty(JpaFacetDataModelProperties.CONNECTION); - if ( ! connection.equals(jpaProject.getDataSource().getConnectionProfileName())) { - change = true; - jpaProject.getDataSource().setConnectionProfileName(connection); - JptCorePlugin.setConnectionProfileName(project, connection); - } - - boolean discover = this.model.getBooleanProperty(JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES); - if (discover != jpaProject.discoversAnnotatedClasses()) { - change = true; - jpaProject.setDiscoversAnnotatedClasses(discover); - JptCorePlugin.setDiscoverAnnotatedClasses(project, discover); - } - - if (platformChange) { - JpaModelManager.instance().rebuildJpaProject(project); - } - if (change) { - buildProject(project); - } - return true; - } - - private static void buildProject(final IProject project) { - IRunnableWithProgress r= new IRunnableWithProgress() { - public void run(IProgressMonitor pm) throws InvocationTargetException { - try { - project.build(IncrementalProjectBuilder.FULL_BUILD, pm); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - } - } - }; - try { - PlatformUI.getWorkbench().getProgressService().run(true, false, r); - } - catch (InterruptedException ie) { /* nothing to do */ } - catch (InvocationTargetException ie) { /* nothing to do */ } - } - - - private final class PlatformGroup - { - final ComboViewer 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)); - // TODO - // PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IDaliHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); - - platformCombo = new ComboViewer(createCombo(group, true)); - platformCombo.setContentProvider( - new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - return CollectionTools.array(JpaPlatformRegistry.instance().jpaPlatformIds()); - } - - public void dispose() { - // do nothing - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - } - ); - platformCombo.setLabelProvider( - new ILabelProvider() { - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return JpaPlatformRegistry.instance().getJpaPlatformLabel((String) element); - } - - public void addListener(ILabelProviderListener listener) { - // do nothing - } - - public void removeListener(ILabelProviderListener listener) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public boolean isLabelProperty(Object element, String property) { - return true; - } - } - ); - platformCombo.addSelectionChangedListener( - new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - model.setProperty(PLATFORM_ID, ((StructuredSelection) platformCombo.getSelection()).getFirstElement()); - } - } - ); - // we need some input here, even if it means absolutely nothing - platformCombo.setInput("null input"); - performDefaults(); - } - - void performDefaults() { - String platformId = getJpaProject().getJpaPlatform().getId(); - model.setProperty(PLATFORM_ID, platformId); - platformCombo.setSelection(new StructuredSelection(platformId)); - } - } - - - private final class ConnectionGroup - { - final Combo connectionCombo; - - private Link connectionLink; - - - public ConnectionGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_connectionLabel); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - connectionCombo = createCombo(group, true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION); - connectionCombo.addSelectionListener( - new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - model.setProperty(CONNECTION, connectionCombo.getItem(connectionCombo.getSelectionIndex())); - } - } - ); - fillConnections(); - - 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(); - } - } - ); - performDefaults(); - } - - private void fillConnections() { - //clear out connection entries from previous login. - connectionCombo.removeAll(); - - for (Iterator<String> stream = JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNames(); stream.hasNext(); ) { - connectionCombo.add(stream.next()); - } - } - - void performDefaults() { - String connectionName = getJpaProject().getDataSource().getConnectionProfileName(); - model.setProperty(CONNECTION, connectionName); - if (connectionName == null) { - connectionCombo.clearSelection(); - } - else { - connectionCombo.setText(connectionName); - } - } - - void openNewConnectionWizard() { - String connectionName = DTPUiTools.createNewProfile(); - if (connectionName != null) { - fillConnections(); - model.setProperty(CONNECTION, connectionName); - connectionCombo.select(connectionCombo.indexOf(connectionName)); - } - } - } - - - private final class PersistentClassManagementGroup - { - final Button discoverClassesButton; - - 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); - discoverClassesButton.addSelectionListener( - new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, true); - } - } - ); - - listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); - listClassesButton.addSelectionListener( - new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, false); - } - } - ); - - model.addListener( - new IDataModelListener() { - public void propertyChanged(DataModelEvent event) { - if (DISCOVER_ANNOTATED_CLASSES.equals(event.getPropertyName())) { - boolean discoverClasses = ((Boolean) event.getProperty()).booleanValue(); - discoverClassesButton.setSelection(discoverClasses); - listClassesButton.setSelection(! discoverClasses); - } - } - } - ); - - performDefaults(); - } - - void performDefaults() { - boolean discoverClasses = getJpaProject().discoversAnnotatedClasses(); - model.setProperty(DISCOVER_ANNOTATED_CLASSES, Boolean.valueOf(discoverClasses)); - discoverClassesButton.setSelection(discoverClasses); - listClassesButton.setSelection(! discoverClasses); - } - } -}
\ No newline at end of file |