Author: xcoulon
Date: 2012-01-24 11:53:11 -0500 (Tue, 24 Jan 2012)
New Revision: 38108
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsContentProvider.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPageModel.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsDialog.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
Log:
Incomplete - JBIDE-10528 - Improve OpenShift UI
https://issues.jboss.org/browse/JBIDE-10528
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2012-01-24
16:53:11 UTC (rev 38108)
@@ -37,7 +37,7 @@
org.eclipse.core.expressions;bundle-version="3.4.300",
org.eclipse.wst.common.modulecore;bundle-version="1.2.101",
org.jboss.ide.eclipse.as.wtp.core;bundle-version="2.3.0",
- org.eclipse.ui.forms;bundle-version="3.5.101"
+ org.eclipse.ui.forms;bundle-version="3.5.100"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.jboss.tools.common.databinding,
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2012-01-24
16:37:04 UTC (rev 38107)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2012-01-24
16:53:11 UTC (rev 38108)
@@ -14,13 +14,27 @@
</category>
<wizard
category="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.category"
-
class="org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ImportProjectWizard"
+
class="org.jboss.tools.openshift.express.internal.ui.wizard.CreateNewApplicationWizard"
icon="icons/openshift-logo-white-icon.png"
-
id="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.ImportProjectNewWizard"
- name="OpenShift Express Application">
+
id="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.createNewApplicationWizard"
+ name="Create a new OpenShift Express Application">
</wizard>
</extension>
<extension
+ point="org.eclipse.ui.importWizards">
+ <category
+ id="org.jboss.tools.openshift.express.ui.wizard.importCategory"
+ name="OpenShift">
+ </category>
+ <wizard
+
category="org.jboss.tools.openshift.express.ui.wizard.importCategory"
+
class="org.jboss.tools.openshift.express.internal.ui.wizard.ImportExistingApplicationWizard"
+ icon="icons/openshift-logo-white-icon.png"
+
id="org.jboss.tools.openshift.express.ui.importExistingApplicationWizard"
+ name="Import an existing OpenShift Express Application">
+ </wizard>
+ </extension>
+ <extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.jboss.tools.common.ui.JBossPerspective">
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftApplicationWizardModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftApplicationWizardModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,312 @@
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.tools.openshift.egit.ui.util.EGitUIUtils;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ConfigureGitSharedProject;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ConfigureUnsharedProject;
+import org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ImportNewProject;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ServerAdapterFactory;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+public class AbstractOpenShiftApplicationWizardModel extends ObservableUIPojo {
+
+ protected HashMap<String, Object> dataModel = new HashMap<String,
Object>();
+ public static final String NEW_PROJECT = "enableProject";
+ public static final String USER = "user";
+ public static final String APPLICATION = "application";
+ public static final String REMOTE_NAME = "remoteName";
+ public static final String REPOSITORY_PATH = "repositoryPath";
+ public static final String PROJECT_NAME = "projectName";
+ public static final String MERGE_URI = "mergeUri";
+ public static final String RUNTIME_DELEGATE = "runtimeDelegate";
+
+ public static final String CREATE_SERVER_ADAPTER = "createServerAdapter";
+ public static final String PUBLICATION_MODE = "serverMode";
+ public static final String PUBLISH_SOURCE = "publishSource";
+ public static final String PUBLISH_BINARY = "publishBinary";
+ public static final String SERVER_TYPE = "serverType";
+
+ public static final String NEW_PROJECT_REMOTE_NAME_DEFAULT = "origin";
+ public static final String EXISTING_PROJECT_REMOTE_NAME_DEFAULT =
"openshift";
+ public static final String DEFAULT_REPOSITORY_PATH =
EGitUIUtils.getEGitDefaultRepositoryPath();
+
+ public AbstractOpenShiftApplicationWizardModel() {
+ super();
+ // default value(s)
+ setNewProject(true);
+ setCreateServerAdapter(true);
+ setRepositoryPath(DEFAULT_REPOSITORY_PATH);
+ setRemoteName(NEW_PROJECT_REMOTE_NAME_DEFAULT);
+ setServerType(ServerCore.findServerType("org.jboss.tools.openshift.express.openshift.server.type"));
+ setPublicationMode(PUBLISH_SOURCE);
+ }
+
+
+ /**
+ * Imports the project that the user has chosen into the workspace.
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @throws OpenShiftException
+ * @throws CoreException
+ * @throws InterruptedException
+ * @throws URISyntaxException
+ * @throws InvocationTargetException
+ */
+ public void importProject(IProgressMonitor monitor) throws OpenShiftException,
CoreException, InterruptedException,
+ URISyntaxException, InvocationTargetException {
+ List<IProject> importedProjects = new ImportNewProject(getProjectName(),
getApplication(), getRemoteName(),
+ getRepositoryFile()).execute(monitor);
+ createServerAdapter(monitor, importedProjects);
+ }
+
+ /**
+ * Enables the user chosen, unshared project to be used on the chosen
+ * OpenShift application. Clones the application git repository, copies the
+ * configuration files to the user project (in the workspace), shares the
+ * user project with git and creates the server adapter.
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @throws URISyntaxException
+ * The OpenShift application repository could not be cloned,
+ * because the uri it is located at is not a valid git uri
+ * @throws OpenShiftException
+ *
+ * @throws InvocationTargetException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation failed.
+ * @throws InterruptedException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation was interrupted.
+ * @throws IOException
+ * The configuration files could not be copied from the git
+ * clone to the user project
+ * @throws CoreException
+ * The user project could not be shared with the git
+ */
+ public void configureUnsharedProject(IProgressMonitor monitor)
+ throws OpenShiftException, InvocationTargetException, InterruptedException,
IOException, CoreException,
+ URISyntaxException {
+ List<IProject> importedProjects = new ConfigureUnsharedProject(
+ getProjectName()
+ , getApplication()
+ , getRemoteName()
+ , getUser())
+ .execute(monitor);
+ createServerAdapter(monitor, importedProjects);
+ }
+
+ /**
+ * Enables the user chosen, unshared project to be used on the chosen
+ * OpenShift application. Clones the application git repository, copies the
+ * configuration files to the user project (in the workspace), adds the
+ * appication git repo as remote and creates the server adapter.
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @throws URISyntaxException
+ * The OpenShift application repository could not be cloned,
+ * because the uri it is located at is not a valid git uri
+ * @throws OpenShiftException
+ *
+ * @throws InvocationTargetException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation failed.
+ * @throws InterruptedException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation was interrupted.
+ * @throws IOException
+ * The configuration files could not be copied from the git
+ * clone to the user project
+ * @throws CoreException
+ * The user project could not be shared with the git
+ */
+ public void configureGitSharedProject(IProgressMonitor monitor)
+ throws OpenShiftException, InvocationTargetException, InterruptedException,
IOException, CoreException,
+ URISyntaxException {
+ List<IProject> importedProjects = new ConfigureGitSharedProject(
+ getProjectName()
+ , getApplication()
+ , getRemoteName()
+ , getUser())
+ .execute(monitor);
+ createServerAdapter(monitor, importedProjects);
+ }
+
+ private void createServerAdapter(IProgressMonitor monitor, List<IProject>
importedProjects)
+ throws OpenShiftException {
+ Assert.isTrue(importedProjects.size() > 0);
+ IProject project = importedProjects.get(0);
+ new ServerAdapterFactory().create(project, this, monitor);
+ }
+
+ public File getRepositoryFile() {
+ String repositoryPath = getRepositoryPath();
+ if (repositoryPath == null || repositoryPath.length() == 0) {
+ return null;
+ }
+ return new File(repositoryPath, getApplicationName());
+ }
+
+ public Object setProperty(String key, Object value) {
+ Object oldVal = dataModel.get(key);
+ dataModel.put(key, value);
+ firePropertyChange(key, oldVal, value);
+ return value;
+ }
+
+ public Object getProperty(String key) {
+ return dataModel.get(key);
+ }
+
+ public void setUser(IUser user) {
+ setProperty(USER, user);
+ }
+
+ public IUser getUser() {
+ return (IUser) getProperty(USER);
+ }
+
+ public IApplication getApplication() {
+ return (IApplication) getProperty(APPLICATION);
+ }
+
+ public String getApplicationName() {
+ String applicationName = null;
+ IApplication application = getApplication();
+ if (application != null) {
+ applicationName = application.getName();
+ }
+ return applicationName;
+ }
+
+ public ICartridge getApplicationCartridge() {
+ ICartridge cartridge = null;
+ IApplication application = getApplication();
+ if (application != null) {
+ cartridge = application.getCartridge();
+ }
+ return cartridge;
+ }
+
+ public String getApplicationCartridgeName() {
+ String cartridgeName = null;
+ ICartridge cartridge = getApplicationCartridge();
+ if (cartridge != null) {
+ cartridgeName = cartridge.getName();
+ }
+ return cartridgeName;
+ }
+
+ public void setApplication(IApplication application) {
+ setProperty(APPLICATION, application);
+ }
+
+ public String setRemoteName(String remoteName) {
+ setProperty(REMOTE_NAME, remoteName);
+ return remoteName;
+ }
+
+ public String getRemoteName() {
+ return (String) getProperty(REMOTE_NAME);
+ }
+
+ public String setRepositoryPath(String repositoryPath) {
+ return (String) setProperty(REPOSITORY_PATH, repositoryPath);
+ }
+
+ public String getRepositoryPath() {
+ return (String) getProperty(REPOSITORY_PATH);
+ }
+
+ public boolean isNewProject() {
+ return (Boolean) getProperty(NEW_PROJECT);
+ }
+
+ public boolean isExistingProject() {
+ return !((Boolean) getProperty(NEW_PROJECT));
+ }
+
+ public Boolean setNewProject(boolean newProject) {
+ return (Boolean) setProperty(NEW_PROJECT, newProject);
+ }
+
+ public Boolean setExistingProject(boolean existingProject) {
+ return (Boolean) setProperty(NEW_PROJECT, !existingProject);
+ }
+
+ public String setProjectName(String projectName) {
+ return (String) setProperty(PROJECT_NAME, projectName);
+ }
+
+ public boolean isGitSharedProject() {
+ return EGitUtils.isSharedWithGit(getProject());
+ }
+
+ private IProject getProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
+ }
+ public Boolean setCreateServerAdapter(Boolean createServerAdapter) {
+ return (Boolean) setProperty(CREATE_SERVER_ADAPTER, createServerAdapter);
+ }
+
+ public String getProjectName() {
+ return (String) getProperty(PROJECT_NAME);
+ }
+
+ public String setMergeUri(String mergeUri) {
+ return (String) setProperty(MERGE_URI, mergeUri);
+ }
+
+ public String getMergeUri() {
+ return (String) getProperty(MERGE_URI);
+ }
+
+ public IRuntime getRuntime() {
+ return (IRuntime) getProperty(RUNTIME_DELEGATE);
+ }
+
+ public String getMode() {
+ return (String) getProperty(PUBLICATION_MODE);
+ }
+
+ public boolean isCreateServerAdapter() {
+ Boolean isCreateServer = (Boolean) getProperty(CREATE_SERVER_ADAPTER);
+ return isCreateServer != null && isCreateServer.booleanValue();
+ }
+
+ public IServerType getServerType() {
+ return (IServerType) getProperty(SERVER_TYPE);
+ }
+
+ public void setServerType(IServerType serverType) {
+ setProperty(SERVER_TYPE, serverType);
+ }
+
+ private void setPublicationMode(String mode) {
+ setProperty(PUBLICATION_MODE, mode);
+ }
+
+
+}
\ No newline at end of file
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -19,8 +19,9 @@
import com.openshift.express.client.OpenShiftException;
/**
- * @author André Dietisheim
+ * @author Andr� Dietisheim
* @author Rob Stryker
+ * @author Xavier Coulon
*/
public class AdapterWizardPageModel extends ObservableUIPojo {
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,567 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateListStrategy;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.conversion.Converter;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.ISWTObservableValue;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.osgi.util.NLS;
+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.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.Table;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;
+import org.jboss.tools.openshift.express.internal.ui.wizard.CreationLogDialog.LogEntry;
+
+import com.openshift.express.client.Cartridge;
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.NotFoundOpenShiftException;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ */
+public class ApplicationConfigurationWizardPage extends AbstractOpenShiftWizardPage {
+
+ private CheckboxTableViewer viewer;
+ private ApplicationConfigurationWizardPageModel pageModel;
+ private CreateNewApplicationWizardModel wizardModel;
+
+ public ApplicationConfigurationWizardPage(IWizard wizard,
CreateNewApplicationWizardModel wizardModel) {
+ super("Application Configuration", "Configure the application you want
to create.",
+ "Application configuration", wizard);
+ this.wizardModel = wizardModel;
+ this.pageModel = new ApplicationConfigurationWizardPageModel(wizardModel);
+ }
+
+ @Override
+ protected void doCreateControls(Composite container, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().applyTo(container);
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL,
SWT.FILL).applyTo(container);
+ createApplicationConfigurationGroup(container, dbc);
+ }
+
+ private void createApplicationConfigurationGroup(Composite parent, DataBindingContext
dbc) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL,
SWT.FILL).applyTo(container);
+
+ Label applicationNameLabel = new Label(container, SWT.NONE);
+ applicationNameLabel.setText("Name:");
+ GridDataFactory.fillDefaults().grab(false, false).align(SWT.FILL,
SWT.FILL).applyTo(applicationNameLabel);
+ Text applicationNameText = new Text(container, SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL,
SWT.FILL).applyTo(applicationNameText);
+ UIUtils.selectAllOnFocus(applicationNameText);
+ final IObservableValue applicationNameModelObservable = BeanProperties.value(
+ ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME).observe(pageModel);
+ final ISWTObservableValue applicationNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(
+ applicationNameText);
+ dbc.bindValue(applicationNameTextObservable, applicationNameModelObservable);
+ final IObservableValue applicationNameStatusObservable = BeanProperties.value(
+ ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME_STATUS).observe(pageModel);
+
+ Label applicationTypeLabel = new Label(container, SWT.NONE);
+ applicationTypeLabel.setText("Type:");
+ GridDataFactory.fillDefaults().grab(false, false).align(SWT.FILL, SWT.CENTER).span(1,
1)
+ .applyTo(applicationTypeLabel);
+ Combo cartridgesCombo = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false)
+ .applyTo(cartridgesCombo);
+ fillCartridgesCombo(dbc, cartridgesCombo);
+ final ISWTObservableValue cartridgesComboObservable =
WidgetProperties.selection().observe(cartridgesCombo);
+ final IObservableValue selectedCartridgeModelObservable = BeanProperties.value(
+ NewApplicationWizardPageModel.PROPERTY_SELECTED_CARTRIDGE).observe(pageModel);
+ dbc.bindValue(cartridgesComboObservable, selectedCartridgeModelObservable,
+ new UpdateValueStrategy().setConverter(new StringToCartridgeConverter()),
+ new UpdateValueStrategy().setConverter(new CartridgeToStringConverter()));
+ final ApplicationInputValidator applicationInputValidator = new
ApplicationInputValidator(
+ applicationNameTextObservable, cartridgesComboObservable);
+ dbc.addValidationStatusProvider(applicationInputValidator);
+ final ApplicationNameValidator applicationNameValidator = new
ApplicationNameValidator(
+ applicationNameStatusObservable, applicationNameTextObservable);
+ dbc.addValidationStatusProvider(applicationNameValidator);
+ ControlDecorationSupport.create(applicationNameValidator, SWT.LEFT | SWT.TOP);
+
+ // embeddable cartridges
+ Group cartridgesGroup = new Group(container, SWT.NONE);
+ cartridgesGroup.setText("Embeddable Cartridges");
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2,
1).applyTo(cartridgesGroup);
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(cartridgesGroup);
+
+ Composite tableContainer = new Composite(cartridgesGroup, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(1,
2).hint(SWT.DEFAULT, 250)
+ .applyTo(tableContainer);
+ this.viewer = createTable(tableContainer);
+ Button checkAllButton = new Button(cartridgesGroup, SWT.PUSH);
+ checkAllButton.setText("&Select All");
+ GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false,
false).align(SWT.FILL, SWT.TOP)
+ .applyTo(checkAllButton);
+ checkAllButton.addSelectionListener(onCheckAll());
+
+ Button uncheckAllButton = new Button(cartridgesGroup, SWT.PUSH);
+ uncheckAllButton.setText("&Deselect All");
+ GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false, true).align(SWT.FILL,
SWT.TOP)
+ .applyTo(uncheckAllButton);
+ uncheckAllButton.addSelectionListener(onUncheckAll());
+ // bottom filler
+ Composite spacer = new Composite(container, SWT.NONE);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(spacer);
+
+ }
+
+ private void fillCartridgesCombo(DataBindingContext dbc, Combo cartridgesCombo) {
+ dbc.bindList(WidgetProperties.items().observe(cartridgesCombo),
+ BeanProperties.list(ApplicationConfigurationWizardPageModel.PROPERTY_CARTRIDGES).observe(pageModel),
+ new UpdateListStrategy(UpdateListStrategy.POLICY_NEVER),
+ new UpdateListStrategy().setConverter(new CartridgeToStringConverter()));
+ }
+
+ protected CheckboxTableViewer createTable(Composite tableContainer) {
+ Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL
| SWT.H_SCROLL
+ | SWT.CHECK);
+ table.setLinesVisible(true);
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableContainer.setLayout(tableLayout);
+ CheckboxTableViewer viewer = new CheckboxTableViewer(table);
+ viewer.setComparer(new EqualityComparer());
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.addCheckStateListener(onCartridgeChecked());
+ createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
+
+ @Override
+ public void update(ViewerCell cell) {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) cell.getElement();
+ cell.setText(cartridge.getName());
+ }
+ }, viewer, tableLayout);
+ return viewer;
+ }
+
+ private void createTableColumn(String name, int weight, CellLabelProvider
cellLabelProvider, TableViewer viewer,
+ TableColumnLayout layout) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
+ column.getColumn().setText(name);
+ column.setLabelProvider(cellLabelProvider);
+ layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ }
+
+ private ICheckStateListener onCartridgeChecked() {
+ return new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ try {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ if (event.getChecked()) {
+ if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
+ addPhpMyAdminCartridge(cartridge);
+ } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
+ addJenkinsCartridge(cartridge);
+ } else {
+ addCartridge(cartridge);
+ }
+ } else {
+ if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
+ removeMySQLCartridge(cartridge);
+ } else {
+ removeCartridge(cartridge);
+ }
+ }
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
+ }
+ }
+ };
+ }
+
+ private void addJenkinsCartridge(final IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ if (pageModel.hasApplication(ICartridge.JENKINS_14)) {
+ pageModel.getSelectedEmbeddableCartridges().add(cartridge);
+ } else {
+ final JenkinsApplicationDialog dialog = new JenkinsApplicationDialog(getShell());
+ if (dialog.open() == Dialog.OK) {
+ createJenkinsApplication(cartridge, dialog.getValue());
+ } else {
+ viewer.setChecked(cartridge, false);
+ }
+ }
+ }
+
+ private void createJenkinsApplication(final IEmbeddableCartridge cartridge, final String
name) {
+ try {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating jenkins application
\"{0}\"...", name)) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ IApplication jenkinsApplication = pageModel.createJenkinsApplication(name,
monitor);
+ pageModel.getSelectedEmbeddableCartridges().add(cartridge);
+
+ openLogDialog(jenkinsApplication);
+
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ getShell().getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ viewer.setChecked(cartridge, false);
+ }
+ });
+ return OpenShiftUIActivator.createErrorStatus("Could not load embeddable
cartridges", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ private void addPhpMyAdminCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
+ if (MessageDialog.openQuestion(getShell(), "Embed mysql cartridge",
+ "To embed phpmyadmin, you'd also have to embed mysql.")) {
+ pageModel.getSelectedEmbeddableCartridges().add(IEmbeddableCartridge.MYSQL_51);
+ pageModel.getSelectedEmbeddableCartridges().add(cartridge);
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
+ } else {
+ viewer.setChecked(cartridge, false);
+ }
+ } else {
+ pageModel.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+ }
+
+ private void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException {
+ pageModel.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
+ private void removeMySQLCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ List<IEmbeddableCartridge> checkedCartridges =
pageModel.getSelectedEmbeddableCartridges();
+ if (viewer.getChecked(IEmbeddableCartridge.PHPMYADMIN_34)) {
+ if (MessageDialog.openQuestion(getShell(), "Remove phpmyadmin cartridge",
+ "If you remove the mysql cartridge, you'd also have to remove
phpmyadmin.")) {
+ checkedCartridges.remove(IEmbeddableCartridge.PHPMYADMIN_34);
+ checkedCartridges.remove(cartridge);
+ viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
+ } else {
+ viewer.setChecked(cartridge, true);
+ }
+ } else {
+ checkedCartridges.remove(cartridge);
+ }
+ }
+
+ private void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException
{
+ pageModel.getSelectedEmbeddableCartridges().remove(cartridge);
+ }
+
+ private SelectionListener onCheckAll() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ viewer.setAllChecked(true);
+ try {
+ addJenkinsCartridge(IEmbeddableCartridge.JENKINS_14);
+ } catch (OpenShiftException ex) {
+ OpenShiftUIActivator.log("Could not select jenkins cartridge", ex);
+ }
+ }
+
+ };
+ }
+
+ private SelectionListener onUncheckAll() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ viewer.setAllChecked(false);
+ }
+
+ };
+ }
+
+ private void clearViewer() {
+ setViewerInput(new ArrayList<IEmbeddableCartridge>());
+ }
+
+ private void setViewerCheckedElements(final Collection<IEmbeddableCartridge>
cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setCheckedElements(cartridges.toArray());
+ }
+ });
+ }
+
+ private void setViewerInput(final Collection<IEmbeddableCartridge> cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setInput(cartridges);
+ }
+ });
+ }
+
+ private static final class CartridgeToStringConverter extends Converter {
+ private CartridgeToStringConverter() {
+ super(Object.class, String.class);
+ }
+
+ @Override
+ public Object convert(Object fromObject) {
+ if (!(fromObject instanceof ICartridge)) {
+ return null;
+ }
+ return ((ICartridge) fromObject).getName();
+ }
+ }
+
+ private static final class StringToCartridgeConverter extends Converter {
+ private StringToCartridgeConverter() {
+ super(String.class, ICartridge.class);
+ }
+
+ @Override
+ public Object convert(Object fromObject) {
+ if (fromObject instanceof String && ((String) fromObject).length() > 0) {
+ return new Cartridge(((String) fromObject));
+ }
+ return null;
+ }
+ }
+
+ private static class JenkinsApplicationDialog extends InputDialog {
+
+ public JenkinsApplicationDialog(Shell shell) {
+ super(shell, "New Jenkins application",
+ "To embed jenkins into your application, you'd first have to create a
jenkins application.\n"
+ + "Please provide a name for your jenkins application:", null, new
JenkinsNameValidator());
+ }
+
+ private static class JenkinsNameValidator implements IInputValidator {
+
+ @Override
+ public String isValid(String input) {
+ if (StringUtils.isEmpty(input)) {
+ return "You have to provide a name for the jenkins application";
+ }
+ return null;
+ }
+ }
+ }
+
+
+ private void openLogDialog(final IApplication application) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ new CreationLogDialog(getShell(), new LogEntry(application.getName(),
application.getCreationLog()))
+ .open();
+ }
+ });
+ }
+
+ /**
+ * Viewer element comparer based on #equals(). The default implementation in
CheckboxTableViewer compares elements
+ * based on instance identity.
+ * <p>
+ * We need this since the available cartridges (item listed in the viewer) are not the
same instance as the ones in
+ * the embedded application (items to check in the viewer).
+ */
+ private static class EqualityComparer implements IElementComparer {
+
+ @Override
+ public boolean equals(Object thisObject, Object thatObject) {
+ if (thisObject == null) {
+ return thatObject != null;
+ }
+
+ if (thatObject == null) {
+ return false;
+ }
+
+ return thisObject.equals(thatObject);
+ }
+
+ @Override
+ public int hashCode(Object element) {
+ return element.hashCode();
+ }
+
+ }
+
+ @Override
+ protected void onPageActivated(final DataBindingContext dbc) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading application cartridges...") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ pageModel.loadCartridges();
+ return Status.OK_STATUS;
+ } catch (NotFoundOpenShiftException e) {
+ // no domain and therefore no applications present
+ clearViewer();
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load application cartridges", e);
+ }
+ }
+ }, getContainer(), getDataBindingContext());
+ WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ setViewerInput(pageModel.loadEmbeddableCartridges());
+ return Status.OK_STATUS;
+ } catch (NotFoundOpenShiftException e) {
+ // no domain and therefore no applications present
+ clearViewer();
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load embeddable cartridges", e);
+ }
+ }
+ }, getContainer(), getDataBindingContext());
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+
+ class ApplicationNameValidator extends MultiValidator {
+
+ private final IObservableValue applicationNameStatusObservable;
+
+ private final ISWTObservableValue applicationNameTextObservable;
+
+ public ApplicationNameValidator(IObservableValue applicationNameStatusObservable,
+ ISWTObservableValue applicationNameTextObservable) {
+ this.applicationNameStatusObservable = applicationNameStatusObservable;
+ this.applicationNameTextObservable = applicationNameTextObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final IStatus applicationNameStatus = (IStatus)
applicationNameStatusObservable.getValue();
+ if (applicationNameStatus != null) {
+ return applicationNameStatus;
+ }
+ return ValidationStatus.ok();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(applicationNameTextObservable);
+ return targets;
+ }
+
+ }
+
+ class ApplicationInputValidator extends MultiValidator {
+
+ private final ISWTObservableValue applicationNameTextObservable,
cartridgesComboObservable;
+
+ public ApplicationInputValidator(ISWTObservableValue applicationNameTextObservable,
+ ISWTObservableValue cartridgesComboObservable) {
+ this.applicationNameTextObservable = applicationNameTextObservable;
+ this.cartridgesComboObservable = cartridgesComboObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final String applicationName = (String) applicationNameTextObservable.getValue();
+ final String applicationType = (String) cartridgesComboObservable.getValue();
+ if (applicationName == null || applicationName.isEmpty() || applicationType == null
+ || applicationType.isEmpty()) {
+ return ValidationStatus
+ .cancel("Please input a name and select a type for the OpenShift application
you want to create.");
+ }
+ return ValidationStatus.ok();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(applicationNameTextObservable);
+ return targets;
+ }
+
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ *
+ */
+public class ApplicationConfigurationWizardPageModel extends ObservableUIPojo {
+
+ public static final String PROPERTY_CARTRIDGES = "cartridges";
+ public static final String PROPERTY_EMBEDDABLE_CARTRIDGES =
"embeddableCartridges";
+ public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
+ public static final String PROPERTY_APPLICATION_NAME = "applicationName";
+ public static final String PROPERTY_APPLICATION_NAME_STATUS =
"applicationNameStatus";
+
+ private CreateNewApplicationWizardModel wizardModel;
+
+ List<ICartridge> cartridges = new ArrayList<ICartridge>();
+ private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
+ private String applicationName;
+ private IStatus applicationNameStatus;
+ private ICartridge selectedCartridge;
+
+ public ApplicationConfigurationWizardPageModel(CreateNewApplicationWizardModel
wizardModel) {
+ this.wizardModel = wizardModel;
+ }
+
+ public IUser getUser() {
+ return wizardModel.getUser();
+ }
+
+ public void loadCartridges() throws OpenShiftException {
+ setCartridges(wizardModel.getUser().getCartridges());
+ }
+
+ public void setCartridges(List<ICartridge> cartridges) {
+ firePropertyChange(PROPERTY_CARTRIDGES, this.cartridges, this.cartridges =
cartridges);
+ }
+
+ public List<ICartridge> getCartridges() {
+ return cartridges;
+ }
+
+ public ICartridge getSelectedCartridge() {
+ return selectedCartridge;
+ }
+
+ public void setSelectedCartridge(ICartridge cartridge) {
+ wizardModel.setApplicationCartridge(cartridge);
+ firePropertyChange(PROPERTY_SELECTED_CARTRIDGE, selectedCartridge,
this.selectedCartridge = cartridge);
+ validateApplicationName();
+ }
+
+ public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
+ List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().getEmbeddableCartridges();
+ setEmbeddableCartridges(cartridges);
+ return cartridges;
+ }
+
+ public void setApplicationName(String applicationName) {
+ wizardModel.setApplicationName(applicationName);
+ firePropertyChange(PROPERTY_APPLICATION_NAME, this.applicationName,
this.applicationName = applicationName);
+ validateApplicationName();
+ }
+
+ public String getApplicationName() {
+ return this.applicationName;
+ }
+
+ public void setApplicationNameStatus(IStatus applicationNameStatus) {
+ firePropertyChange(PROPERTY_APPLICATION_NAME_STATUS, this.applicationNameStatus,
+ this.applicationNameStatus = applicationNameStatus);
+ }
+
+ public IStatus getApplicationNameStatus() {
+ return this.applicationNameStatus;
+ }
+
+ public IStatus validateApplicationName() {
+ IStatus status = Status.OK_STATUS;
+ final String applicationName = getApplicationName();
+ if (!applicationName.matches("\\S+")) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "The application name must not contain spaces.");
+ }
+ setApplicationNameStatus(status);
+ return status;
+ }
+
+ public void setEmbeddableCartridges(List<IEmbeddableCartridge> cartridges) {
+ firePropertyChange(PROPERTY_EMBEDDABLE_CARTRIDGES, this.embeddableCartridges,
+ this.embeddableCartridges = cartridges);
+ }
+
+ public List<IEmbeddableCartridge> getEmbeddableCartridges() {
+ return embeddableCartridges;
+ }
+
+ public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException {
+ return wizardModel.getSelectedEmbeddableCartridges();
+ }
+
+ public boolean hasApplication(ICartridge cartridge) {
+ try {
+ return wizardModel.getUser().hasApplication(cartridge);
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(OpenShiftUIActivator
+ .createErrorStatus("Could not get application by cartridge", e));
+ return false;
+ }
+ }
+
+ public IApplication getApplication() {
+ return wizardModel.getApplication();
+ }
+
+ public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
+ return wizardModel.createApplication(name, ICartridge.JENKINS_14, monitor);
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsContentProvider.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsContentProvider.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsContentProvider.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,186 @@
+/**
+ *
+ */
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class ApplicationDetailsContentProvider implements ITreeContentProvider {
+
+ private IApplication application;
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof IApplication) {
+ try {
+ final SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd 'at'
HH:mm:ss");
+ final ContainerElement infoContainer = new ContainerElement("info", null);
+ infoContainer.add(new SimpleElement("Name", application.getName(),
infoContainer));
+ infoContainer.add(new SimpleElement("Public URL",
application.getApplicationUrl().toString(), true,
+ infoContainer));
+ infoContainer.add(new SimpleElement("Type",
application.getCartridge().getName(), infoContainer));
+ infoContainer.add(new SimpleElement("Created on",
format.format(application.getCreationTime()),
+ infoContainer));
+ infoContainer.add(new SimpleElement("UUID", application.getUUID(),
infoContainer));
+ infoContainer.add(new SimpleElement("Git URL", application.getGitUri(),
infoContainer));
+ final ContainerElement cartridgesContainer = new
ContainerElement("Cartridges", infoContainer);
+ infoContainer.add(cartridgesContainer);
+ for (IEmbeddableCartridge cartridge : application.getEmbeddedCartridges()) {
+ cartridgesContainer.add(new SimpleElement(cartridge.getName(),
cartridge.getUrl().toString(), true,
+ cartridgesContainer));
+ }
+ return new Object[] { infoContainer };
+ } catch (OpenShiftException e) {
+ Logger.error("Failed to display details for OpenShift application", e);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof ContainerElement) {
+ return ((ContainerElement) parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ if (element instanceof SimpleElement) {
+ return ((SimpleElement) element).getParent();
+ } else if (element instanceof ContainerElement) {
+ return ((ContainerElement) element).getParent();
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return (element instanceof ContainerElement);
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof IApplication) {
+ this.application = (IApplication) newInput;
+ } else {
+ this.application = null;
+ }
+
+ }
+
+ static class SimpleElement {
+
+ private final String property;
+ private final String value;
+ private final ContainerElement parent;
+ private final boolean isLink;
+
+ public SimpleElement(String property, String value, ContainerElement parent) {
+ super();
+ this.property = property;
+ this.value = value;
+ this.parent = parent;
+ this.isLink = false;
+ }
+
+ public SimpleElement(String property, String value, boolean isLink, ContainerElement
parent) {
+ super();
+ this.property = property;
+ this.value = value;
+ this.parent = parent;
+ this.isLink = isLink;
+ }
+
+ /**
+ * @return the property
+ */
+ public final String getProperty() {
+ return property;
+ }
+
+ /**
+ * @return the value
+ */
+ public final String getValue() {
+ return value;
+ }
+
+ /**
+ * @return the parent container
+ */
+ public final ContainerElement getParent() {
+ return parent;
+ }
+
+ /**
+ * @return the isLink
+ */
+ public boolean isLink() {
+ return isLink;
+ }
+ }
+
+ static class ContainerElement {
+
+ private final String property;
+ private final List<Object> children;
+ private final ContainerElement parent;
+
+ public ContainerElement(String property, ContainerElement parent) {
+ this.property = property;
+ this.children = new ArrayList<Object>();
+ this.parent = parent;
+ }
+
+ /**
+ * @return the property
+ */
+ public final String getProperty() {
+ return property;
+ }
+
+ public final void add(SimpleElement child) {
+ children.add(child);
+ }
+
+ public final void add(ContainerElement child) {
+ children.add(child);
+ }
+
+ /**
+ * @return the value
+ */
+ public final Object[] getChildren() {
+ return children.toArray();
+ }
+
+ /**
+ * @return the parent container
+ */
+ public final ContainerElement getParent() {
+ return parent;
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsContentProvider.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsDialog.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsDialog.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationDetailsDialog.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -17,27 +17,38 @@
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TreeColumnLayout;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.TextStyle;
+import org.eclipse.swt.layout.GridData;
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.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
import org.jboss.tools.common.ui.BrowserUtil;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftImages;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
import com.openshift.express.client.IApplication;
-import com.openshift.express.client.IEmbeddableCartridge;
-import com.openshift.express.client.utils.RFC822DateUtils;
/**
- * @author André Dietisheim
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
*/
public class ApplicationDetailsDialog extends TitleAreaDialog {
@@ -57,81 +68,159 @@
@Override
protected Control createDialogArea(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(container);
- GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).spacing(14,
4).applyTo(container);
+ Label titleSeparator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.TOP).grab(true,
false).applyTo(titleSeparator);
- Label separator = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
- GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.TOP).grab(true,
false).applyTo(separator);
+ Composite treeTableContainer = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).grab(true,
true).minSize(SWT.DEFAULT, 250)
+ .applyTo(treeTableContainer);
+ GridLayoutFactory.fillDefaults().margins(6, 6).spacing(14,
4).applyTo(treeTableContainer);
+ TreeViewer viewer = createApplicationDetailsTable(treeTableContainer);
+ fillApplicationDetailsTable(viewer);
- createDetails("Name:", application.getName(), container);
- createDetails("Type:", application.getCartridge().getName(), container);
- createDetails("Embedded Cartridges:", new
ErrorMessageCallable<String>("Embedded Cartridges") {
+ Label buttonsSeparator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.TOP).grab(true,
false).applyTo(buttonsSeparator);
- @Override
- public String call() throws Exception {
- return StringUtils.toString(application.getEmbeddedCartridges(),
- new StringUtils.ToStringConverter<IEmbeddableCartridge>() {
+ // createDetails("Name:", application.getName(), treeTableContainer);
+ // createDetails("Type:", application.getCartridge().getName(),
treeTableContainer);
+ // createDetails("Embedded Cartridges:", new
ErrorMessageCallable<String>("Embedded Cartridges") {
+ //
+ // @Override
+ // public String call() throws Exception {
+ // return StringUtils.toString(application.getEmbeddedCartridges(),
+ // new StringUtils.ToStringConverter<IEmbeddableCartridge>() {
+ //
+ // @Override
+ // public String toString(IEmbeddableCartridge cartridge) {
+ // return cartridge.getName();
+ // }
+ // });
+ // }
+ //
+ // }.get(), treeTableContainer);
+ // createDetails("Creation Time:", new
ErrorMessageCallable<String>("Creation Time") {
+ //
+ // @Override
+ // public String call() throws Exception {
+ // return RFC822DateUtils.getString(application.getCreationTime());
+ // }
+ // }.get(), treeTableContainer);
+ // createDetails("UUIDxx:", new
ErrorMessageCallable<String>("UUID") {
+ //
+ // @Override
+ // public String call() throws Exception {
+ // return application.getUUID();
+ // }
+ // }.get(), treeTableContainer);
+ // createDetails("Git URL:", new ErrorMessageCallable<String>("Git
URL") {
+ //
+ // @Override
+ // public String call() throws Exception {
+ // return application.getGitUri();
+ // }
+ // }.get(), treeTableContainer);
+ //
+ // Label publicUrlLabel = new Label(treeTableContainer, SWT.NONE);
+ // publicUrlLabel.setText("Public URL:");
+ // GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(publicUrlLabel);
+ // Link publicUrlLink = new Link(treeTableContainer, SWT.WRAP);
+ // String applicationUrl = new ErrorMessageCallable<String>("Public
URL") {
+ //
+ // @Override
+ // public String call() throws Exception {
+ // return application.getApplicationUrl();
+ // }
+ // }.get();
+ // publicUrlLink.setText("<a>" + applicationUrl +
"</a>");
+ // GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(publicUrlLink);
+ // publicUrlLink.addSelectionListener(onPublicUrl(applicationUrl));
- @Override
- public String toString(IEmbeddableCartridge cartridge) {
- return cartridge.getName();
- }
- });
- }
+ return treeTableContainer;
+ }
- }.get(), container);
- createDetails("Creation Time:", new
ErrorMessageCallable<String>("Creation Time") {
+ private void fillApplicationDetailsTable(final TreeViewer viewer) {
+ viewer.setContentProvider(new ApplicationDetailsContentProvider());
+ viewer.setInput(application);
+ viewer.expandToLevel(2);
+ }
+ private TreeViewer createApplicationDetailsTable(Composite tableContainer) {
+ Tree tree = new Tree(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL |
SWT.H_SCROLL);
+ int desiredHeight = tree.getItemHeight() * 10 + tree.getHeaderHeight();
+ GridLayoutFactory.fillDefaults().margins(6, 6).spacing(14, 4).applyTo(tree);
+ GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT,
desiredHeight).applyTo(tree);
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
+
+ TreeColumnLayout treeLayout = new TreeColumnLayout();
+ tableContainer.setLayout(treeLayout);
+ TreeViewer viewer = new TreeViewer(tree);
+ // sure ?
+ viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+ createTreeColumn("Property", 1, new CellLabelProvider() {
@Override
- public String call() throws Exception {
- return RFC822DateUtils.getString(application.getCreationTime());
+ public void update(ViewerCell cell) {
+ if (cell.getElement() instanceof ApplicationDetailsContentProvider.SimpleElement) {
+ ApplicationDetailsContentProvider.SimpleElement element =
(ApplicationDetailsContentProvider.SimpleElement) cell
+ .getElement();
+ cell.setText(element.getProperty());
+ } else if (cell.getElement() instanceof
ApplicationDetailsContentProvider.ContainerElement) {
+ ApplicationDetailsContentProvider.ContainerElement element =
(ApplicationDetailsContentProvider.ContainerElement) cell
+ .getElement();
+ cell.setText(element.getProperty());
+ }
}
- }.get(), container);
- createDetails("UUID:", new
ErrorMessageCallable<String>("UUID") {
+ }, viewer, treeLayout);
+ createTreeColumn("Value", 1, new StyledCellLabelProvider() {
@Override
- public String call() throws Exception {
- return application.getUUID();
- }
- }.get(), container);
- createDetails("Git URL:", new ErrorMessageCallable<String>("Git
URL") {
+ public void update(ViewerCell cell) {
+ if (cell.getElement() instanceof ApplicationDetailsContentProvider.SimpleElement) {
+ ApplicationDetailsContentProvider.SimpleElement element =
(ApplicationDetailsContentProvider.SimpleElement) cell
+ .getElement();
+ cell.setText(element.getValue());
+ if (element.isLink()) {
+ Styler style = new Styler() {
+ @Override
+ public void applyStyles(TextStyle textStyle) {
+ textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
+ textStyle.underline = true;
+ }
- @Override
- public String call() throws Exception {
- return application.getGitUri();
+ };
+ StyledString styledString = new StyledString(cell.getText(), style);
+ cell.setStyleRanges(styledString.getStyleRanges());
+ cell.setText(styledString.getString());
+ //cell.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_HAND));
+ }
+ }
}
- }.get(), container);
+ }, viewer, treeLayout);
- Label publicUrlLabel = new Label(container, SWT.NONE);
- publicUrlLabel.setText("Public URL:");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(publicUrlLabel);
- Link publicUrlLink = new Link(container, SWT.WRAP);
- String applicationUrl = new ErrorMessageCallable<String>("Public URL")
{
+ return viewer;
- @Override
- public String call() throws Exception {
- return application.getApplicationUrl();
- }
- }.get();
- publicUrlLink.setText("<a>" + applicationUrl +
"</a>");
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(publicUrlLink);
- publicUrlLink.addSelectionListener(onPublicUrl(applicationUrl));
+ }
- return container;
+ private void createTreeColumn(String name, int weight, CellLabelProvider
cellLabelProvider, TreeViewer treeViewer,
+ TreeColumnLayout layout) {
+ final TreeViewerColumn viewerColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
+ final TreeColumn column = viewerColumn.getColumn();
+ column.setText(name);
+ column.setResizable(true);
+ viewerColumn.setLabelProvider(cellLabelProvider);
+ layout.setColumnData(column, new ColumnWeightData(weight, true));
}
private void setupDialog(Composite parent) {
parent.getShell().setText("Application Details");
- setTitle(NLS.bind("Application {0}", application.getName()));
+ setTitle(NLS.bind("Details of Application {0}", application.getName()));
setTitleImage(OpenShiftImages.OPENSHIFT_LOGO_WHITE_MEDIUM_IMG);
setDialogHelpAvailable(false);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
- true);
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
}
private SelectionAdapter onPublicUrl(final String applicationUrl) {
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPage.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPage.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.wizard.IWizard;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.common.ui.databinding.DataBindingUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.NotFoundOpenShiftException;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ */
+public class ApplicationSelectionWizardPage extends AbstractOpenShiftWizardPage {
+
+ private TableViewer tableViewer;
+ private final ApplicationSelectionWizardPageModel pageModel;
+
+ public ApplicationSelectionWizardPage(IWizard wizard,
AbstractOpenShiftApplicationWizardModel wizardModel) {
+ super("Application selection", "Click 'next' or select another
application to import.",
+ "Application selection", wizard);
+ this.pageModel = new ApplicationSelectionWizardPageModel(wizardModel);
+ }
+
+ @Override
+ protected void doCreateControls(Composite container, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);
+ createApplicationsGroup(container, dbc);
+ }
+
+ /**
+ * Creates the SWT Group in which a table which will display the existing applications
with their corresponding
+ * type. Before each application, a radio button will let the user choose which
application to import in his
+ * workspace.
+ *
+ * @param container
+ * @param dbc
+ */
+ private void createApplicationsGroup(Composite container, DataBindingContext dbc) {
+ Label applicationLabel = new Label(container, SWT.NONE);
+ applicationLabel.setText("Existing Applications on OpenShift");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).span(5,
1).applyTo(applicationLabel);
+ // GridLayoutFactory.fillDefaults().numColumns(4).margins(6,
6).applyTo(applicationGroup);
+
+ Composite tableContainer = new Composite(container, SWT.NONE);
+ this.tableViewer = createTable(tableContainer);
+
+ GridDataFactory.fillDefaults().span(1, 2).align(SWT.FILL, SWT.FILL).grab(true, false)
+ //.hint(SWT.DEFAULT, desiredHeight)
+ .applyTo(tableContainer);
+ tableViewer.addDoubleClickListener(onApplicationDoubleClick());
+ Binding selectedApplicationBinding =
dbc.bindValue(ViewerProperties.singleSelection().observe(tableViewer),
+ BeanProperties.value(ApplicationWizardPageModel.PROPERTY_SELECTED_APPLICATION).observe(pageModel),
+ new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
+ @Override
+ public IStatus validate(Object value) {
+ if (value != null) {
+ return ValidationStatus.ok();
+ } else {
+ return ValidationStatus.cancel("Select an application in the list
below.");
+ }
+ }
+ }), null);
+
+ Button refreshButton = new Button(container, SWT.PUSH);
+ refreshButton.setText("R&efresh");
+ GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).grab(false, false).hint(80,
SWT.DEFAULT)
+ .applyTo(refreshButton);
+ // DataBindingUtils.bindEnablementToValidationStatus(refreshButton, IStatus.OK, dbc,
+ // selectedApplicationBinding);
+ refreshButton.addSelectionListener(onRefresh(dbc));
+
+ Button detailsButton = new Button(container, SWT.PUSH);
+ detailsButton.setText("De&tails");
+ GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).grab(false, true).hint(80,
SWT.DEFAULT)
+ .applyTo(detailsButton);
+ DataBindingUtils.bindEnablementToValidationStatus(detailsButton, IStatus.OK, dbc,
selectedApplicationBinding);
+ detailsButton.addSelectionListener(onDetails(dbc));
+ // bottom filler
+ Composite spacer = new Composite(container, SWT.NONE);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true)
+ .applyTo(spacer);
+
+ }
+
+ private IDoubleClickListener onApplicationDoubleClick() {
+ return new IDoubleClickListener() {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ openDetailsDialog();
+ }
+ };
+ }
+
+ protected TableViewer createTable(Composite tableContainer) {
+ Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL
| SWT.H_SCROLL);
+ int desiredHeight = table.getItemHeight() * 10 + table.getHeaderHeight();
+ GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT,
desiredHeight).applyTo(table);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableContainer.setLayout(tableLayout);
+ TableViewer viewer = new TableViewer(table);
+ viewer.setContentProvider(new ArrayContentProvider());
+ createTableColumn("Name", 1, new CellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IApplication application = (IApplication) cell.getElement();
+ cell.setText(application.getName());
+ }
+ }, viewer, tableLayout);
+
+ createTableColumn("Type", 1, new CellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IApplication application = (IApplication) cell.getElement();
+ cell.setText(application.getCartridge().getName());
+ }
+ }, viewer, tableLayout);
+
+ createTableColumn("URL", 3, new CellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IApplication application = (IApplication) cell.getElement();
+ try {
+ cell.setText(application.getApplicationUrl());
+ } catch (OpenShiftException e) {
+ }
+ }
+ }, viewer, tableLayout);
+
+ return viewer;
+ }
+
+ private void createTableColumn(String name, int weight, CellLabelProvider
cellLabelProvider, TableViewer viewer,
+ TableColumnLayout layout) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
+ column.getColumn().setText(name);
+ column.getColumn().setResizable(true);
+ column.setLabelProvider(cellLabelProvider);
+ layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ }
+
+ private SelectionAdapter onRefresh(final DataBindingContext dbc) {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading applications...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ final Collection<IApplication> applications = pageModel.getApplications();
+ setViewerInput(applications);
+ return Status.OK_STATUS;
+ } catch (NotFoundOpenShiftException e) {
+ // no domain and therefore no applications present
+ clearViewer();
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load applications", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ };
+ }
+
+ private SelectionAdapter onDetails(DataBindingContext dbc) {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openDetailsDialog();
+ }
+ };
+ }
+
+ private void openDetailsDialog() {
+ new ApplicationDetailsDialog(pageModel.getSelectedApplication(), getShell()).open();
+ }
+
+ @Override
+ protected void onPageActivated(final DataBindingContext dbc) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading applications...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ final Collection<IApplication> applications = pageModel.getApplications();
+ setViewerInput(applications);
+ return Status.OK_STATUS;
+ } catch (NotFoundOpenShiftException e) {
+ // no domain and therefore no applications present
+ clearViewer();
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Could not
load applications",
+ e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+
+ private void clearViewer() {
+ Logger.debug("Clearing applications list in viewer");
+ setViewerInput(new ArrayList<IApplication>());
+ }
+
+ private void setViewerInput(final Collection<IApplication> applications) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ Logger.debug("Setting {} application(s) in the viewer",
applications.size());
+ tableViewer.setInput(applications);
+ }
+ });
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ *
+ */
+public class ApplicationSelectionWizardPageModel extends ObservableUIPojo {
+
+ public static final String PROPERTY_NAMESPACE = "namespace";
+ public static final String PROPERTY_DOMAIN = "domain";
+ public static final String PROPERTY_SELECTED_APPLICATION =
"selectedApplication";
+
+ private IApplication selectedApplication;
+ private AbstractOpenShiftApplicationWizardModel wizardModel;
+
+ public ApplicationSelectionWizardPageModel(AbstractOpenShiftApplicationWizardModel
wizardModel) {
+ this.wizardModel = wizardModel;
+ }
+
+ public List<IApplication> getApplications() throws OpenShiftException {
+ IUser user = getUser();
+ if (user == null) {
+ return Collections.emptyList();
+ }
+ return user.getApplications();
+ }
+
+ public IApplication getSelectedApplication() {
+ return selectedApplication;
+ }
+
+ public void setSelectedApplication(IApplication application) {
+ wizardModel.setApplication(application);
+ firePropertyChange(PROPERTY_SELECTED_APPLICATION, this.selectedApplication,
this.selectedApplication = application);
+ }
+
+ public void destroyCurrentApplication() throws OpenShiftException {
+ if (selectedApplication == null) {
+ return;
+ }
+
+ selectedApplication.destroy();
+ }
+
+ public IUser getUser() {
+ return wizardModel.getUser();
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationSelectionWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -64,10 +64,6 @@
this.cartridge = cartridge;
}
- public void createApplication(IProgressMonitor monitor) throws OpenShiftException {
- IApplication application = createApplication(name, cartridge, monitor);
- setApplication(application);
- }
public void setApplication(IApplication application) {
firePropertyChange(PROPERTY_APPLICATION, this.application, this.application =
application);
@@ -77,6 +73,10 @@
return application;
}
+ public void createApplication(IProgressMonitor monitor) throws OpenShiftException {
+ IApplication application = createApplication(name, cartridge, monitor);
+ setApplication(application);
+ }
public IApplication createApplication(String name, ICartridge cartridge,
IProgressMonitor monitor) throws OpenShiftException {
// monitor.subTask("creating application...");
IApplication application = getUser().createApplication(name, cartridge);
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizard.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizard.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+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.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.errors.TransportException;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.jboss.tools.common.ui.DelegatingProgressMonitor;
+import org.jboss.tools.common.ui.JobUtils;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.ui.ImportFailedException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.WontOverwriteException;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ */
+public class CreateNewApplicationWizard extends Wizard implements INewWizard {
+
+ private CreateNewApplicationWizardModel wizardModel;
+
+ public CreateNewApplicationWizard() {
+ this.wizardModel = new CreateNewApplicationWizardModel();
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public void addPages() {
+ this.wizardModel = new CreateNewApplicationWizardModel();
+ addPage(new CredentialsWizardPage(this, wizardModel));
+ addPage(new ApplicationConfigurationWizardPage(this, wizardModel));
+ addPage(new ProjectAndServerAdapterSettingsWizardPage(this, wizardModel));
+ addPage(new GitCloningSettingsWizardPage(this, wizardModel));
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean performFinish() {
+ boolean successfull = true;
+ if (wizardModel.getApplication() == null) {
+ successfull = processApplicationCreation();
+
+ }
+ if (successfull) {
+ successfull = processCartridges();
+ }
+ if(successfull) {
+ try {
+ final DelegatingProgressMonitor delegatingMonitor = new DelegatingProgressMonitor();
+ Future<IStatus> jobResult =
+ WizardUtils.runInWizard(
+ new ImportJob(delegatingMonitor),
+ delegatingMonitor, getContainer());
+ return JobUtils.isOk(jobResult.get(10, TimeUnit.SECONDS));
+ } catch (Exception e) {
+ ErrorDialog.openError(getShell(), "Error", "Could not create local git
repository.",
+ new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "An exception occurred while creating local git repository.", e));
+ return false;
+ }
+ }
+ return successfull;
+ }
+
+ private boolean processApplicationCreation() {
+ final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
+ try {
+ WizardUtils.runInWizard(
+ new Job(NLS.bind("Creating application \"{0}\"...",
wizardModel.getApplicationName())) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ wizardModel.createApplication(monitor);
+ queue.offer(true);
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ queue.offer(false);
+ return OpenShiftUIActivator.createErrorStatus("Could not create
application", e);
+ }
+ }
+
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private boolean processCartridges() {
+ final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
+ try {
+ WizardUtils.runInWizard(
+ new Job(NLS.bind("Adding selected embedded cartridges for application
{0}...", wizardModel
+ .getApplication().getName())) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+
+ List<IEmbeddableCartridge> selectedCartridges = wizardModel
+ .getSelectedEmbeddableCartridges();
+ final IApplication application = wizardModel.getApplication();
+ if (selectedCartridges != null && !selectedCartridges.isEmpty()) {
+ application.addEmbbedCartridges(selectedCartridges);
+ }
+ queue.offer(true);
+ } catch (OpenShiftException e) {
+ queue.offer(false);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, NLS.bind(
+ "Could not embed cartridges to application {0}",
wizardModel.getApplication()
+ .getName()), e);
+ }
+ return Status.OK_STATUS;
+ }
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private boolean isTransportException(InvocationTargetException e) {
+ return e.getTargetException() instanceof JGitInternalException
+ && e.getTargetException().getCause() instanceof TransportException;
+ }
+
+ private TransportException getTransportException(InvocationTargetException e) {
+ if (isTransportException(e)) {
+ return (TransportException) ((JGitInternalException)
e.getTargetException()).getCause();
+ }
+ return null;
+ }
+
+ private void openError(final String title, final String message) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(getShell(), title, message);
+ }
+ });
+ }
+
+ private boolean askForConfirmation(final String message, final String applicationName)
{
+ final boolean[] confirmed = new boolean[1];
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ confirmed[0] = MessageDialog.openConfirm(
+ getShell(),
+ NLS.bind("Import OpenShift Application ", applicationName),
+ message);
+ }
+ });
+ return confirmed[0];
+ }
+
+ /**
+ * A workspace job that will create a new project or enable the selected
+ * project to be used with OpenShift.
+ */
+ private class ImportJob extends WorkspaceJob {
+
+ private DelegatingProgressMonitor delegatingMonitor;
+
+ public ImportJob(DelegatingProgressMonitor delegatingMonitor) {
+ super("Importing project to workspace...");
+ this.delegatingMonitor = delegatingMonitor;
+ }
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ try {
+ delegatingMonitor.add(monitor);
+
+ if (wizardModel.isNewProject()) {
+ wizardModel.importProject(delegatingMonitor);
+ } else if (!wizardModel.isGitSharedProject()) {
+ if (!askForConfirmation(
+ NLS.bind("OpenShift application {0} will be enabled on project {1} by "
+
+ "copying OpenShift configuration and enabling Git for the project.\n "
+
+ "This cannot be undone. Do you wish to continue ?",
+ wizardModel.getApplicationName(), wizardModel.getProjectName()),
+ wizardModel.getApplicationName())) {
+ return Status.CANCEL_STATUS;
+ }
+ wizardModel.configureUnsharedProject(delegatingMonitor);
+ } else {
+ if (!askForConfirmation(
+ NLS.bind("OpenShift application {0} will be enabled on project {1} by copying
OpenShift " +
+ "configuration and adding the OpenShift git repo as remote.\n " +
+ "This cannot be undone. Do you wish to continue ?",
+ wizardModel.getApplicationName(), wizardModel.getProjectName()),
+ wizardModel.getApplicationName())) {
+ return Status.CANCEL_STATUS;
+ }
+ wizardModel.configureGitSharedProject(delegatingMonitor);
+ }
+
+ return Status.OK_STATUS;
+ } catch (final WontOverwriteException e) {
+ openError("Project already present", e.getMessage());
+ return Status.CANCEL_STATUS;
+ } catch (final ImportFailedException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import maven project {0}.", e,
+ wizardModel.getProjectName());
+ } catch (IOException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not copy openshift configuration files to project {0}", e,
+ wizardModel.getProjectName());
+ } catch (OpenShiftException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import project to the workspace.", e);
+ } catch (URISyntaxException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "The url of the remote git repository is not valid", e);
+ } catch (InvocationTargetException e) {
+ if (isTransportException(e)) {
+ TransportException te = getTransportException(e);
+ return OpenShiftUIActivator
+ .createErrorStatus(
+ "Could not clone the repository. Authentication failed.\n"
+ + " Please make sure that you added your private key to the ssh
preferences.",
+ te);
+ } else {
+ return OpenShiftUIActivator.createErrorStatus(
+ "An exception occurred while creating local git repository.", e);
+ }
+ } catch (Exception e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import project to the workspace.", e);
+ } finally {
+ delegatingMonitor.done();
+ }
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizard.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizardModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizardModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,88 @@
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osgi.util.NLS;
+import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.OpenShiftApplicationNotAvailableException;
+import com.openshift.express.client.OpenShiftException;
+
+public class CreateNewApplicationWizardModel extends
AbstractOpenShiftApplicationWizardModel {
+
+ /**
+ * Timeout in seconds when trying to contact an application after it had been created.
+ */
+ private static final int APP_CREATION_TIMEOUT = 10;
+ private static final String APPLICATION_NAME = "applicationName";
+ private static final String APPLICATION_CARTRIDGE = "applicationCartridge";
+ private static final String SELECTED_EMBEDDABLE_CARTRIDGES =
"selectedEmbeddableCartridges";
+
+ public CreateNewApplicationWizardModel() {
+ dataModel.put(NEW_PROJECT, true);
+ }
+
+ private void waitForAccessible(IApplication application, IProgressMonitor monitor)
+ throws OpenShiftApplicationNotAvailableException, OpenShiftException {
+ // monitor.subTask("waiting for application to become accessible...");
+ if (!application.waitForAccessible(APP_CREATION_TIMEOUT * 1000)) {
+ throw new OpenShiftApplicationNotAvailableException(NLS.bind(
+ OpenShiftExpressUIMessages.HOSTNAME_NOT_ANSWERING,
application.getApplicationUrl()));
+ }
+ }
+
+ public IApplication createApplication(String name, ICartridge cartridge,
IProgressMonitor monitor) throws OpenShiftApplicationNotAvailableException,
OpenShiftException {
+ IApplication application = getUser().createApplication(name, cartridge);
+ waitForAccessible(application, monitor);
+ return application;
+ }
+
+ public void createApplication(IProgressMonitor monitor) throws OpenShiftException {
+ IApplication application = createApplication(getApplicationName(),
getApplicationCartridge(), monitor);
+ setApplication(application);
+ }
+
+ @Override
+ public String getApplicationName() {
+ return (String) dataModel.get(APPLICATION_NAME);
+ }
+
+ public void setApplicationName(String applicationName) {
+ dataModel.put(APPLICATION_NAME, applicationName);
+ }
+
+ public void setApplicationCartridge(ICartridge cartridge) {
+ dataModel.put(APPLICATION_CARTRIDGE, cartridge);
+ }
+
+ @Override
+ public ICartridge getApplicationCartridge() {
+ return (ICartridge)dataModel.get(APPLICATION_CARTRIDGE);
+ }
+
+ @Override
+ public String getApplicationCartridgeName() {
+ final ICartridge cartridge = (ICartridge)dataModel.get(APPLICATION_CARTRIDGE);
+ if(cartridge != null) {
+ return cartridge.getName();
+ }
+ return null;
+ }
+
+ public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() {
+ @SuppressWarnings("unchecked")
+ List<IEmbeddableCartridge> selectedEmbeddableCartridges =
(List<IEmbeddableCartridge>) dataModel.get(SELECTED_EMBEDDABLE_CARTRIDGES);
+ if(selectedEmbeddableCartridges == null) {
+ selectedEmbeddableCartridges = new ArrayList<IEmbeddableCartridge>();
+ dataModel.put(SELECTED_EMBEDDABLE_CARTRIDGES, selectedEmbeddableCartridges);
+ }
+ return selectedEmbeddableCartridges;
+ }
+
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreateNewApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -14,15 +14,19 @@
import java.util.concurrent.TimeUnit;
import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
-import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.ISWTObservableValue;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
@@ -30,106 +34,83 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.BrowserUtil;
+import org.jboss.tools.common.ui.DelegatingProgressMonitor;
import org.jboss.tools.common.ui.WizardUtils;
-import org.jboss.tools.common.ui.databinding.DataBindingUtils;
import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;
-import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ImportProjectWizardModel;
/**
- * @author André Dietisheim
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
*/
public class CredentialsWizardPage extends AbstractOpenShiftWizardPage {
protected static final String OPENSHIFT_EXPRESS_SIGNUP_URL =
"https://openshift.redhat.com/app/user/new/express"; //$NON-NLS-1$
- private Button validateButton;
+ private final CredentialsWizardPageModel model;
- private CredentialsWizardPageModel model;
+ private Text rhLoginText = null;
+ private Text passwordText = null;
- public CredentialsWizardPage(IWizard wizard, ImportProjectWizardModel wizardModel) {
- super("Server connection", "Please provide the credentials of your user
account on OpenShift Express",
- "Server Connection", wizard);
+ public CredentialsWizardPage(IWizard wizard, AbstractOpenShiftApplicationWizardModel
wizardModel) {
+ super("Server connection", "Please provide your OpenShift Express user
credentials, then click 'next'.", "Server Connection",
+ wizard);
this.model = new CredentialsWizardPageModel(wizardModel);
}
protected void doCreateControls(Composite container, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(container);
- Link signupLink = new Link(container, SWT.WRAP);
- signupLink.setText("If you don't have an account on OpenShift, please sign up
<a>here</a>.");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).hint(SWT.DEFAULT,
30).applyTo(signupLink);
- signupLink.addSelectionListener(onSignupLinkClicked());
+ // This wizard page status and navigation controls are bound to the credentials
validity status:
+ // 1 - No error message is displayed if the credentials validity status is
"OK"
+ // 2 - when the user changes the 'rhLogin' or 'password' field values,
the credentials validity status is set to
+ // "Cancel", thus no error message should appear on the wizard page
+ // 3 - when the 'rhLogin' and the 'password' fields are not null/empty,
the 'next' control button is enabled
+ // 4 - if the credentials validation fails (ie, invalid credentials), the
'next' button is disabled and an error
+ // message is displayed at the top of the wizard page until the 'rhLogin'
and/or the 'password' field values
+ // have been changed. Then back to step 2.
Label rhLoginLabel = new Label(container, SWT.NONE);
rhLoginLabel.setText("&Username");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(rhLoginLabel);
- Text rhLoginText = new Text(container, SWT.BORDER);
+ rhLoginText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2,
1).applyTo(rhLoginText);
UIUtils.selectAllOnFocus(rhLoginText);
- DataBindingUtils.bindMandatoryTextField(
- rhLoginText, "Username", CredentialsWizardPageModel.PROPERTY_RHLOGIN,
model, dbc);
-
+ final IObservableValue rhLoginObservable =
BeanProperties.value(CredentialsWizardPageModel.PROPERTY_RHLOGIN)
+ .observe(model);
+ dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(rhLoginText),
rhLoginObservable);
+
Label passwordLabel = new Label(container, SWT.NONE);
passwordLabel.setText("&Password");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);
- Text passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD);
+ passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2,
1).applyTo(passwordText);
UIUtils.selectAllOnFocus(passwordText);
- DataBindingUtils.bindMandatoryTextField(
- passwordText, "Password", CredentialsWizardPageModel.PROPERTY_PASSWORD,
model, dbc);
+ final IObservableValue passwordModelObservable =
BeanProperties.value(CredentialsWizardPageModel.PROPERTY_PASSWORD)
+ .observe(model);
+ final ISWTObservableValue passwordTextObservable =
WidgetProperties.text(SWT.Modify).observe(passwordText);
+ dbc.bindValue(passwordTextObservable, passwordModelObservable);
+
+ IObservableValue credentialsStatusObservable = BeanProperties.value(
+ CredentialsWizardPageModel.PROPERTY_CREDENTIALS_STATUS).observe(model);
+ dbc.addValidationStatusProvider(new CredentialsInputValidator(rhLoginObservable,
+ passwordModelObservable));
+ final CredentialsStatusValidator credentialsStatusValidator = new
CredentialsStatusValidator(credentialsStatusObservable, passwordTextObservable);
+ dbc.addValidationStatusProvider(credentialsStatusValidator);
+ ControlDecorationSupport.create(credentialsStatusValidator, SWT.LEFT | SWT.TOP);
- Label spacerLabel = new Label(container, SWT.None);
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(spacerLabel);
-
- this.validateButton = new Button(container, SWT.NONE);
- validateButton.setText("&Validate");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).indent(0,
10).hint(100, SWT.DEFAULT)
- .applyTo(validateButton);
- DataBindingUtils.bindEnablementToValidationStatus(
- validateButton
- , IStatus.INFO
- , dbc);
- validateButton.addSelectionListener(onValidate(dbc));
- dbc.bindValue(
- new WritableValue(null, IStatus.class),
- BeanProperties.value(CredentialsWizardPageModel.PROPERTY_CREDENTIALS_VALIDITY).observe(model),
- new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
- new UpdateValueStrategy().setAfterGetValidator(
- new CredentialsStatusValidator()));
-
- setErrorMessage(null);
+ Link signupLink = new Link(container, SWT.WRAP);
+ signupLink.setText("If you don't have an account on OpenShift, please sign up
<a>here</a>.");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).hint(SWT.DEFAULT,
30).applyTo(signupLink);
+ signupLink.addSelectionListener(onSignupLinkClicked());
}
- protected SelectionAdapter onValidate(final DataBindingContext dbc) {
- return new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- try {
- WizardUtils.runInWizard(
- new Job("Testing user credentials...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- model.validateCredentials();
- return Status.OK_STATUS;
- }
- }, getContainer(), dbc);
- } catch (Exception ex) {
- // ignore
- }
- };
- };
- }
-
protected SelectionAdapter onSignupLinkClicked() {
return new SelectionAdapter() {
@@ -144,49 +125,108 @@
@Override
protected void setupWizardPageSupport(DataBindingContext dbc) {
- ParametrizableWizardPageSupport.create(
- IStatus.ERROR | IStatus.CANCEL, this,
- dbc);
+ ParametrizableWizardPageSupport.create(IStatus.ERROR | IStatus.CANCEL, this, dbc);
}
@Override
+ protected void onPageActivated(DataBindingContext dbc) {
+ super.onPageActivated(dbc);
+ if (model.getRhLogin() == null || model.getRhLogin().isEmpty() && rhLoginText
!= null) {
+ rhLoginText.setFocus();
+ } else if (passwordText != null) {
+ passwordText.setFocus();
+ }
+ }
+
+ @Override
protected void onPageWillGetDeactivated(Direction direction, PageChangingEvent event,
DataBindingContext dbc) {
if (direction == Direction.BACKWARDS) {
return;
}
-
- if (!model.areCredentialsValidated()) {
+
+ if (!model.areCredentialsValid()) {
try {
final ArrayBlockingQueue<IStatus> queue = new
ArrayBlockingQueue<IStatus>(1);
- WizardUtils.runInWizard(
- new Job("Testing user credentials...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- IStatus status = model.validateCredentials();
- queue.offer(status);
- return Status.OK_STATUS;
- }
- }, getContainer(), getDatabindingContext());
+ WizardUtils.runInWizard(new Job("Verifying user credentials...") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IStatus status = model.validateCredentials();
+ queue.offer(status);
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ }, new DelegatingProgressMonitor(), getContainer(), getDatabindingContext());
queue.poll(10, TimeUnit.SECONDS);
event.doit = model.areCredentialsValid();
+ if(!event.doit) {
+ passwordText.setFocus();
+ passwordText.selectAll();
+ }
} catch (Exception ex) {
event.doit = false;
+ } finally {
}
+
}
}
- private static class CredentialsStatusValidator implements IValidator {
- public IStatus validate(Object value) {
- if (value instanceof IStatus) {
- int currentSeverity = ((IStatus) value).getSeverity();
- if (currentSeverity < IStatus.ERROR) {
- return ValidationStatus.ok();
- }
- } else if (value == null) {
- return ValidationStatus.info("You have to validate your credentials");
+ class CredentialsInputValidator extends MultiValidator {
+
+ private final IObservableValue rhLoginObservable;
+
+ private final IObservableValue passwordObservable;
+
+ public CredentialsInputValidator(IObservableValue rhLoginObservable,
+ IObservableValue passwordObservable) {
+ this.rhLoginObservable = rhLoginObservable;
+ this.passwordObservable = passwordObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ // set the wizard page status to OK as soon as a user types something..
+ final String rhLoginValue = (String) rhLoginObservable.getValue();
+ final String passwordValue = (String) passwordObservable.getValue();
+ if (rhLoginValue != null && !rhLoginValue.isEmpty() && passwordValue
!= null && !passwordValue.isEmpty()) {
+ return ValidationStatus.ok();
}
- return ValidationStatus.error("The given credentials are not valid");
+ return ValidationStatus.cancel("Please provide your OpenShift Express user
credentials");
}
}
+
+ class CredentialsStatusValidator extends MultiValidator {
+
+ private final IObservableValue credentialsStatusObservable;
+
+ private final IObservableValue passwordTextObservable;
+
+ public CredentialsStatusValidator(IObservableValue credentialsStatusObservable,
IObservableValue passwordTextObservable) {
+ this.credentialsStatusObservable = credentialsStatusObservable;
+ this.passwordTextObservable = passwordTextObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final IStatus credentialsValidityStatus = (IStatus)
credentialsStatusObservable.getValue();
+
+ if (credentialsValidityStatus != null) {
+ final IStatus credentialsValidity = model.getCredentialsStatus();
+ return credentialsValidity;
+ }
+ return ValidationStatus.ok();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(passwordTextObservable);
+ return targets;
+ }
+
+
+ }
+
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -10,14 +10,11 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.io.IOException;
-
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ImportProjectWizardModel;
import com.openshift.express.client.IUser;
import com.openshift.express.client.NotFoundOpenShiftException;
@@ -29,29 +26,30 @@
import com.openshift.express.client.configuration.UserConfiguration;
/**
- * @author André Dietisheim
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
*/
public class CredentialsWizardPageModel extends ObservableUIPojo {
- private static final String ID = OpenShiftUIActivator.PLUGIN_ID
- + OpenShiftUIActivator.getDefault().getBundle().getVersion();
+ private static final String CLIENT_ID = OpenShiftUIActivator.PLUGIN_ID
+ + " " + OpenShiftUIActivator.getDefault().getBundle().getVersion();
private static final String RHLOGIN_PREFS_KEY =
"org.jboss.tools.openshift.express.internal.ui.wizard.CredentialsWizardModel_RHLOGIN";
public static final String PROPERTY_SERVER_URL = "serverUrl";
public static final String PROPERTY_RHLOGIN = "rhLogin";
public static final String PROPERTY_PASSWORD = "password";
- public static final String PROPERTY_CREDENTIALS_VALIDITY =
"credentialsValidity";
+ public static final String PROPERTY_CREDENTIALS_STATUS = "credentialsStatus";
private String rhLogin;
private String password;
- private IStatus credentialsValidity;
+ private IStatus credentialsStatus;
private IUser user;
private StringPreferenceValue rhLoginPreferenceValue;
- private ImportProjectWizardModel wizardModel;
+ private AbstractOpenShiftApplicationWizardModel wizardModel;
- public CredentialsWizardPageModel(ImportProjectWizardModel model) {
+ public CredentialsWizardPageModel(AbstractOpenShiftApplicationWizardModel model) {
this.wizardModel = model;
this.rhLoginPreferenceValue = new StringPreferenceValue(RHLOGIN_PREFS_KEY,
OpenShiftUIActivator.PLUGIN_ID);
this.rhLogin = initRhLogin();
@@ -112,28 +110,30 @@
}
private void setCredentialsStatus(IStatus status) {
- firePropertyChange(PROPERTY_CREDENTIALS_VALIDITY, this.credentialsValidity,
- this.credentialsValidity = status);
+ firePropertyChange(PROPERTY_CREDENTIALS_STATUS, this.credentialsStatus,
+ this.credentialsStatus = status);
}
- public IStatus getCredentialsValidity() {
- return credentialsValidity;
+ public IStatus getCredentialsStatus() {
+ return credentialsStatus;
}
public boolean areCredentialsValid() {
- IStatus validationStatus = getCredentialsValidity();
+ IStatus validationStatus = getCredentialsStatus();
return validationStatus != null
&& validationStatus.isOK();
}
public boolean areCredentialsValidated() {
- return credentialsValidity != null;
+ return credentialsStatus != null;// && credentialsValidity.isOK();
}
public IStatus validateCredentials() {
IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Your
credentails are not valid.");
try {
- this.user = new User(getRhLogin(), getPassword(), ID);
+ // reset without notifying
+ //this.credentialsValidity = null;
+ this.user = new User(getRhLogin(), getPassword(), CLIENT_ID);
if (user.isValid()) {
status = Status.OK_STATUS;
}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,323 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.IWizardPage;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.ui.databinding.InvertingBooleanConverter;
+import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
+import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Rob Stryker
+ * @author Xavier Coulon
+ *
+ */
+public class GitCloningSettingsWizardPage extends AbstractOpenShiftWizardPage implements
IWizardPage {
+
+ private GitCloningSettingsWizardPageModel pageModel;
+ private Button useDefaultRemoteNameButton;
+ private Button useDefaultRepoPathButton;
+ private Text remoteNameText;
+
+ public GitCloningSettingsWizardPage(CreateNewApplicationWizard wizard,
AbstractOpenShiftApplicationWizardModel model) {
+ super(
+ "Import an existing OpenShift application",
+ "Configure the cloning settings by specifying the clone destination if you
create a new project, and the git remote name if you're using an existing
project.",
+ "Cloning settings", wizard);
+ this.pageModel = new GitCloningSettingsWizardPageModel(model);
+ }
+
+ public GitCloningSettingsWizardPage(ImportExistingApplicationWizard wizard,
AbstractOpenShiftApplicationWizardModel model) {
+ super(
+ "Import an existing OpenShift application",
+ "Configure the cloning settings by specifying the clone destination if you
create a new project, and the git remote name if you're using an existing
project.",
+ "Cloning settings", wizard);
+ this.pageModel = new GitCloningSettingsWizardPageModel(model);
+ }
+
+ @Override
+ protected void doCreateControls(Composite parent, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().applyTo(parent);
+ Composite cloneGroup = createCloneGroup(parent, dbc);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true,
false).applyTo(cloneGroup);
+ Composite filler = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(filler);
+ }
+
+ private Composite createCloneGroup(Composite parent, DataBindingContext dbc) {
+ Group cloneGroup = new Group(parent, SWT.BORDER);
+ cloneGroup.setText("Cloning settings");
+ cloneGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).margins(10, 10)//
.extendedMargins(0, 0, 0, 10)
+ .applyTo(cloneGroup);
+ // Repo Path Management
+ useDefaultRepoPathButton = new Button(cloneGroup, SWT.CHECK);
+ useDefaultRepoPathButton.setText("Use default location");
+ useDefaultRepoPathButton.setToolTipText("Uncheck if you want to use a custom
location for your project");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3,
1).applyTo(useDefaultRepoPathButton);
+ Label labelForRepoPath = new Label(cloneGroup, SWT.NONE);
+ labelForRepoPath.setText("Location:");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false,
false).indent(10, 0)
+ .applyTo(labelForRepoPath);
+ final Text repoPathText = new Text(cloneGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER).grab(true, false)
+ .applyTo(repoPathText);
+ final IObservableValue repoPathTextObservable =
WidgetProperties.text(SWT.Modify).observe(repoPathText);
+ final IObservableValue repoPathModelObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_REPO_PATH).observe(pageModel);
+ ValueBindingBuilder.bind(repoPathTextObservable).to(repoPathModelObservable).in(dbc);
+
+ Button browseRepoPathButton = new Button(cloneGroup, SWT.PUSH);
+ browseRepoPathButton.setText("Browse");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100,
SWT.DEFAULT).applyTo(browseRepoPathButton);
+ browseRepoPathButton.addSelectionListener(onRepoPath());
+
+ final IObservableValue useDefaultRepoButtonSelectionObservable =
WidgetProperties.selection().observe(
+ useDefaultRepoPathButton);
+ final IObservableValue useDefaultRepoModelObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REPO_PATH).observe(pageModel);
+ ValueBindingBuilder.bind(useDefaultRepoButtonSelectionObservable).to(useDefaultRepoModelObservable).in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(repoPathText))
+ .notUpdating(useDefaultRepoModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseRepoPathButton))
+ .notUpdating(useDefaultRepoModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+ // move focus to the project location text control when not choosing the 'Use
default location' option.
+ useDefaultRepoPathButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ repoPathText.setFocus();
+ repoPathText.selectAll();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ IObservableValue repoPathValidityObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REPO_PATH_VALIDITY).observe(pageModel);
+ dbc.addValidationStatusProvider(new
RepoPathValidationStatusProvider(repoPathValidityObservable,
+ repoPathTextObservable));
+
+
+ // Remote Name Management
+ useDefaultRemoteNameButton = new Button(cloneGroup, SWT.CHECK);
+ useDefaultRemoteNameButton.setText("Use default remote name");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3,
1).applyTo(useDefaultRemoteNameButton);
+ useDefaultRemoteNameButton.addSelectionListener(onDefaultRemoteName());
+
+ Label labelForRemoteName = new Label(cloneGroup, SWT.NONE);
+ labelForRemoteName.setText("Remote name:");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false,
false).indent(10, 0)
+ .applyTo(labelForRemoteName);
+ remoteNameText = new Text(cloneGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER)
+ .grab(true, false).applyTo(remoteNameText);
+ Label fillerForRemoteName = new Label(cloneGroup, SWT.NONE);
+ GridDataFactory.fillDefaults().span(1, 1).align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER)
+ .grab(false, false).applyTo(fillerForRemoteName);
+ final IObservableValue remoteNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(remoteNameText);
+ final IObservableValue remoteNameModelObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_REMOTE_NAME).observe(pageModel);
+ ValueBindingBuilder.bind(remoteNameTextObservable).to(remoteNameModelObservable).in(dbc);
+
+ final IObservableValue useDefaultRemoteNameButtonSelectionObservable =
WidgetProperties.selection().observe(
+ useDefaultRemoteNameButton);
+ final IObservableValue useDefaultRemoteNameModelObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REMOTE_NAME).observe(pageModel);
+
+ ValueBindingBuilder.bind(useDefaultRemoteNameButtonSelectionObservable).to(useDefaultRemoteNameModelObservable)
+ .in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(remoteNameText))
+ .notUpdating(useDefaultRemoteNameModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+ // move focus to the project name text control when choosing the 'Use an existing
project' option.
+ useDefaultRemoteNameButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ remoteNameText.setFocus();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ IObservableValue remoteNameValidityObservable = BeanProperties.value(
+ GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY).observe(pageModel);
+ dbc.addValidationStatusProvider(new
RemoteNameValidationStatusProvider(remoteNameValidityObservable,
+ remoteNameTextObservable));
+
+ Link sshPrefsLink = new Link(parent, SWT.NONE);
+ sshPrefsLink.setText("Make sure your SSH key used with the domain is listed in
<a>SSH2 Preferences</a>.");
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).indent(10,
0)
+ .applyTo(sshPrefsLink);
+ sshPrefsLink.addSelectionListener(onSshPrefs());
+
+ return cloneGroup;
+ }
+
+ private SelectionListener onRepoPath() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Choose the location to store your repository clone
to...");
+ String repositoryPath = dialog.open();
+ if (repositoryPath != null) {
+ pageModel.setRepositoryPath(repositoryPath);
+ }
+ }
+ };
+ }
+
+ private SelectionListener onDefaultRemoteName() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ pageModel.resetRemoteName();
+ }
+ };
+ }
+
+ private SelectionAdapter onSshPrefs() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SshPrivateKeysPreferences.openPreferencesPage(getShell());
+ }
+ };
+ }
+
+ protected void onPageActivated(DataBindingContext dbc) {
+ // allow to enable a proj only for as7 openshift applications
+ // setTitle(NLS.bind("Import OpenShift application {0}",
pageModel.getApplicationName()));
+ pageModel.resetRepositoryPath();
+ pageModel.resetRemoteName();
+ if (pageModel.isNewProject()) {
+ useDefaultRepoPathButton.setEnabled(true);
+ useDefaultRemoteNameButton.setEnabled(false);
+ useDefaultRemoteNameButton.setSelection(true);
+ remoteNameText.setEnabled(false);
+ } else {
+ useDefaultRepoPathButton.setEnabled(false);
+ useDefaultRemoteNameButton.setEnabled(true);
+ remoteNameText.setEnabled(!useDefaultRemoteNameButton.getSelection());
+ }
+ // pageModel.getWizardModel().setProperty(AdapterWizardPageModel.MODE,
AdapterWizardPageModel.MODE_SOURCE);
+ onPageActivatedBackground(dbc);
+ }
+
+ protected void onPageActivatedBackground(final DataBindingContext dbc) {
+ /*
+ * new Job("Loading remote OpenShift application") { public IStatus
run(IProgressMonitor monitor) { try {
+ * pageModel.loadGitUri(); pageModel.loadApplicationUrl(); } catch (OpenShiftException
e) { IStatus status =
+ * OpenShiftUIActivator.createErrorStatus(e.getMessage(), e);
OpenShiftUIActivator.log(status); return status; }
+ * return Status.OK_STATUS; } }.schedule();
+ */
+ }
+
+ class RepoPathValidationStatusProvider extends MultiValidator {
+
+ private final IObservableValue repoPathValidityObservable;
+
+ private final IObservableValue repoPathTextObservable;
+
+ public RepoPathValidationStatusProvider(IObservableValue repoPathValidityObservable,
+ IObservableValue repoPathTextObservable) {
+ this.repoPathValidityObservable = repoPathValidityObservable;
+ this.repoPathTextObservable = repoPathTextObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final IStatus repoPathValidityStatus = (IStatus)
repoPathValidityObservable.getValue();
+
+ if (repoPathValidityStatus != null) {
+ return repoPathValidityStatus;
+ }
+ return ValidationStatus.ok();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(repoPathTextObservable);
+ return targets;
+ }
+
+ }
+
+ class RemoteNameValidationStatusProvider extends MultiValidator {
+
+ private final IObservableValue remoteNameValidityObservable;
+
+ private final IObservableValue remoteNameTextObservable;
+
+ public RemoteNameValidationStatusProvider(IObservableValue
remoteNameValidityObservable,
+ IObservableValue remoteNameTextObservable) {
+ this.remoteNameValidityObservable = remoteNameValidityObservable;
+ this.remoteNameTextObservable = remoteNameTextObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final IStatus remoteNameValidityStatus = (IStatus)
remoteNameValidityObservable.getValue();
+
+ if (remoteNameValidityStatus != null) {
+ return remoteNameValidityStatus;
+ }
+ return ValidationStatus.ok();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(remoteNameTextObservable);
+ return targets;
+ }
+
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,363 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import static
org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftApplicationWizardModel.*;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.egit.ui.util.EGitUIUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Rob Stryker
+ * @author Xavier Coulon
+ */
+public class GitCloningSettingsWizardPageModel extends ObservableUIPojo {
+
+ public static final String PROPERTY_NEW_PROJECT = "newProject";
+ public static final String PROPERTY_CLONE_URI = "cloneUri";
+ // public static final String PROPERTY_MERGE_URI = "mergeUri";
+ public static final String PROPERTY_PROJECT_NAME = "projectName";
+ public static final String PROPERTY_APPLICATION_URL = "applicationUrl";
+ public static final String PROPERTY_REPO_PATH = "repositoryPath";
+ public static final String PROPERTY_REMOTE_NAME = "remoteName";
+ public static final String PROPERTY_LOADING = "loading";
+
+ public static final String CREATE_SERVER = "createServer";
+ public static final String MODE = "serverMode";
+ public static final String MODE_SOURCE = "serverModeSource";
+ public static final String MODE_BINARY = "serverModeBinary";
+ public static final String SERVER_TYPE = "serverType";
+
+ public static final String PROPERTY_USE_DEFAULT_REPO_PATH =
"useDefaultRepoPath";
+
+ public static final String PROPERTY_CUSTOM_REPO_PATH_VALIDITY =
"customRepoPathValidity";
+
+ public static final String PROPERTY_USE_DEFAULT_REMOTE_NAME =
"useDefaultRemoteName";
+
+ public static final String PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY =
"customRemoteNameValidity";
+
+ private AbstractOpenShiftApplicationWizardModel wizardModel;
+ private boolean loading;
+
+ private boolean useDefaultRepoPath = true;
+
+ private IStatus customRepoPathValidity = null;
+
+ private IStatus customRemoteNameValidity = null;
+
+ private boolean useDefaultRemoteName = true;
+
+ public GitCloningSettingsWizardPageModel(AbstractOpenShiftApplicationWizardModel
wizardModel) {
+ this.wizardModel = wizardModel;
+ }
+
+ public boolean isNewProject() {
+ return wizardModel.isNewProject();
+ }
+
+ // public void setMergeUri(String mergeUri) {
+ // firePropertyChange(PROPERTY_MERGE_URI, wizardModel.getMergeUri(),
wizardModel.setMergeUri(mergeUri));
+ // }
+ //
+ // public String getMergeUri() {
+ // return wizardModel.getMergeUri();
+ // }
+
+ // public GitUri getKnownMergeUri(String uriOrLabel) {
+ // GitUri gitUri = null;
+ // if (isGitUri(uriOrLabel)) {
+ // gitUri = getKnownMergeUriByUri(uriOrLabel);
+ // } else {
+ // gitUri = getKnownMergeUriByLabel(uriOrLabel);
+ // }
+ // return gitUri;
+ // }
+
+ // private boolean isGitUri(String gitUriString) {
+ // try {
+ // URIish uriish = new URIish(gitUriString);
+ // return uriish.isRemote();
+ // } catch (URISyntaxException e) {
+ // return false;
+ // }
+ // }
+
+ // private GitUri getKnownMergeUriByUri(String gitUriString) {
+ // GitUri matchingGitUri = null;
+ // for (GitUri gitUri : getMergeUris()) {
+ // if (gitUri.getGitUri().equals(gitUriString)) {
+ // matchingGitUri = gitUri;
+ // break;
+ // }
+ // }
+ // return matchingGitUri;
+ // }
+
+ // private GitUri getKnownMergeUriByLabel(String label) {
+ // GitUri matchingGitUri = null;
+ // for (GitUri gitUri : getMergeUris()) {
+ // if (gitUri.getLabel().equals(label)) {
+ // matchingGitUri = gitUri;
+ // break;
+ // }
+ // }
+ // return matchingGitUri;
+ // }
+
+ // public List<GitUri> getMergeUris() {
+ // ArrayList<GitUri> mergeUris = new ArrayList<GitUri>();
+ // mergeUris.add(new GitUri(
+ // "seambooking-example",
"git://github.com/openshift/seambooking-example.git",
+ // ICartridge.JBOSSAS_7));
+ // mergeUris.add(new GitUri(
+ // "tweetstream-example",
"git://github.com/openshift/tweetstream-example.git",
+ // ICartridge.JBOSSAS_7));
+ // mergeUris.add(new GitUri(
+ // "sinatra-example",
"git://github.com/openshift/sinatra-example.git",
+ // new Cartridge("rack-1.1")));
+ // mergeUris.add(new GitUri(
+ // "sugarcrm-example",
"git://github.com/openshift/sugarcrm-example.git",
+ // new Cartridge("php-5.3")));
+ // return mergeUris;
+ // }
+
+ public void loadGitUri() throws OpenShiftException {
+ setLoading(true);
+ setCloneUri("Loading...");
+ setCloneUri(getCloneUri());
+ setLoading(false);
+ }
+
+ private void setCloneUri(String gitUri) {
+ firePropertyChange(PROPERTY_CLONE_URI, null, gitUri);
+ }
+
+ public String getCloneUri() throws OpenShiftException {
+ IApplication application = wizardModel.getApplication();
+ if (application == null) {
+ return null;
+ }
+ return application.getGitUri();
+ }
+
+ public void loadApplicationUrl() throws OpenShiftException {
+ setLoading(true);
+ setApplicationUrl("Loading...");
+ setApplicationUrl(getApplicationUrl());
+ setLoading(false);
+ }
+
+ public String getApplicationUrl() throws OpenShiftException {
+ IApplication application = wizardModel.getApplication();
+ if (application == null) {
+ return null;
+ }
+ return application.getApplicationUrl();
+ }
+
+ public String getApplicationName() {
+ IApplication application = wizardModel.getApplication();
+ if (application == null) {
+ return null;
+ }
+ return application.getName();
+ }
+
+ public boolean isJBossAS7Application() {
+ IApplication application = wizardModel.getApplication();
+ if (application == null) {
+ return false;
+ }
+ return ICartridge.JBOSSAS_7.equals(application.getCartridge());
+ }
+
+ public void setApplicationUrl(String applicationUrl) {
+ firePropertyChange(PROPERTY_APPLICATION_URL, null, applicationUrl);
+ }
+
+ public String getRepositoryPath() {
+ return wizardModel.getRepositoryPath();
+ }
+
+ public void setRepositoryPath(String repositoryPath) {
+ firePropertyChange(PROPERTY_REPO_PATH, wizardModel.getRepositoryPath(),
+ wizardModel.setRepositoryPath(repositoryPath));
+ validateRepoPathProject();
+
+ }
+
+ public void resetRepositoryPath() {
+ if (wizardModel.isNewProject() || getRepositoryPath() == null) {
+ setRepositoryPath(getDefaultRepositoryPath());
+ }
+ }
+
+ public void resetRemoteName() {
+ // if existing project and remote name is still 'origin' -> switch to
'openshift'
+ // (so, if existing project and remote name is not 'origin', leave as-is
+ if (!wizardModel.isNewProject() &&
NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
+ setRemoteName(EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ }
+ // if new project and remote name is not 'origin' -> restore
'origin'
+ else if (wizardModel.isNewProject() &&
!NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
+ setUseDefaultRemoteName(true);
+ setRemoteName(NEW_PROJECT_REMOTE_NAME_DEFAULT);
+ }
+ }
+
+ @Deprecated
+ private String getDefaultRepositoryPath() {
+ return EGitUIUtils.getEGitDefaultRepositoryPath();
+ }
+
+ public String getRemoteName() {
+ return wizardModel.getRemoteName();
+ }
+
+ public void setRemoteName(String remoteName) {
+ firePropertyChange(PROPERTY_REMOTE_NAME, wizardModel.getRemoteName(),
wizardModel.setRemoteName(remoteName));
+ validateRemoteName();
+ }
+
+ public boolean isLoading() {
+ return loading;
+ }
+
+ public void setLoading(boolean loading) {
+ firePropertyChange(PROPERTY_LOADING, this.loading, this.loading = loading);
+ }
+
+ public boolean isCompatibleToApplicationCartridge(ICartridge cartridge) {
+ IApplication application = wizardModel.getApplication();
+ return application != null && application.getCartridge() != null
+ && application.getCartridge().equals(cartridge);
+ }
+
+ public static class GitUri {
+
+ private String label;
+ private String gitUri;
+ private ICartridge cartridge;
+
+ private GitUri(String label, String gitUri, ICartridge cartridge) {
+ this.label = label;
+ this.gitUri = gitUri;
+ this.cartridge = cartridge;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getGitUri() {
+ return gitUri;
+ }
+
+ public String toString() {
+ return getLabel();
+ }
+
+ public ICartridge getCartridge() {
+ return cartridge;
+ }
+
+ public boolean isCompatible(ICartridge cartridge) {
+ return this.cartridge.equals(cartridge);
+ }
+ }
+
+ public void setUseDefaultRepoPath(boolean useDefaultRepoPath) {
+ firePropertyChange(PROPERTY_USE_DEFAULT_REPO_PATH, useDefaultRepoPath,
+ this.useDefaultRepoPath = useDefaultRepoPath);
+ if (this.useDefaultRepoPath) {
+ setRepositoryPath(getDefaultRepositoryPath());
+ } else {
+
+ }
+ validateRepoPathProject();
+ }
+
+ public boolean isUseDefaultRepoPath() {
+ return useDefaultRepoPath;
+ }
+
+ private IStatus validateRepoPathProject() {
+ IStatus status = Status.OK_STATUS;
+ // skip the validation if the user wants to create a new project. The name and state of
the existing project do
+ // not matter...
+ if (!isUseDefaultRepoPath()) {
+ IPath repoPath = new Path(getRepositoryPath());
+ if (repoPath.isEmpty() || !repoPath.isAbsolute() || !repoPath.toFile().canWrite()) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "The path does not exist or is not writeable.");
+ }
+ }
+ setCustomRepoPathValidity(status);
+ return status;
+ }
+
+ public void setCustomRepoPathValidity(IStatus status) {
+ firePropertyChange(PROPERTY_CUSTOM_REPO_PATH_VALIDITY, this.customRepoPathValidity,
+ this.customRepoPathValidity = status);
+ }
+
+ public IStatus getCustomRepoPathValidity() {
+ return this.customRepoPathValidity;
+ }
+
+ public void setUseDefaultRemoteName(boolean useDefaultRemoteName) {
+ firePropertyChange(PROPERTY_USE_DEFAULT_REMOTE_NAME, useDefaultRemoteName,
+ this.useDefaultRemoteName = useDefaultRemoteName);
+ if (useDefaultRemoteName) {
+ setRemoteName(isNewProject() ? NEW_PROJECT_REMOTE_NAME_DEFAULT :
EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ }
+ validateRemoteName();
+ }
+
+ public boolean isUseDefaultRemoteName() {
+ return useDefaultRemoteName;
+ }
+
+ private IStatus validateRemoteName() {
+ IStatus status = Status.OK_STATUS;
+ // skip the validation if the user wants to create a new project. The name and state of
the existing project do
+ // not matter...
+ if (!isUseDefaultRemoteName()) {
+ final String remoteName = getRemoteName();
+ if(remoteName == null || remoteName.isEmpty()) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "The custom
remote name must not be empty.");
+ } else if(!remoteName.matches("\\S+")) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "The custom
remote name must not contain spaces.");
+ }
+ }
+ setCustomRemoteNameValidity(status);
+ return status;
+ }
+
+ public void setCustomRemoteNameValidity(IStatus status) {
+ firePropertyChange(PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY,
this.customRemoteNameValidity,
+ this.customRemoteNameValidity = status);
+ }
+
+ public IStatus getCustomRemoteNameValidity() {
+ return this.customRemoteNameValidity;
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizard.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizard.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+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.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.errors.TransportException;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.jboss.tools.common.ui.DelegatingProgressMonitor;
+import org.jboss.tools.common.ui.JobUtils;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.ui.ImportFailedException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.WontOverwriteException;
+
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ */
+public class ImportExistingApplicationWizard extends Wizard implements IImportWizard {
+
+ private ImportExistingApplicationWizardModel model;
+
+ public ImportExistingApplicationWizard() {
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ setWindowTitle("OpenShift application wizard");
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public boolean performFinish() {
+ try {
+ final DelegatingProgressMonitor delegatingMonitor = new DelegatingProgressMonitor();
+ Future<IStatus> jobResult =
+ WizardUtils.runInWizard(
+ new ImportJob(delegatingMonitor),
+ delegatingMonitor, getContainer());
+ return JobUtils.isOk(jobResult.get(10, TimeUnit.SECONDS));
+ } catch (Exception e) {
+ ErrorDialog.openError(getShell(), "Error", "Could not create local git
repository.",
+ new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "An exception occurred while creating local git repository.", e));
+ return false;
+ }
+ }
+
+ private boolean askForConfirmation(final String applicationName, final String
projectName) {
+ final boolean[] confirmed = new boolean[1];
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ confirmed[0] = MessageDialog.openConfirm(getShell(),
+ NLS.bind("Import OpenShift Application ", applicationName),
+ NLS.bind(
+ "OpenShift application {0} will be enabled on project {1} by copying
OpenShift " +
+ "configuration and enable Git for the project.\n " +
+ "This cannot be undone. Do you wish to continue ?", applicationName,
+ projectName));
+ }
+ });
+ return confirmed[0];
+ }
+
+ @Override
+ public void addPages() {
+ this.model = new ImportExistingApplicationWizardModel();
+ addPage(new CredentialsWizardPage(this, model));
+ addPage(new ApplicationSelectionWizardPage(this, model));
+ addPage(new ProjectAndServerAdapterSettingsWizardPage(this, model));
+ addPage(new GitCloningSettingsWizardPage(this, model));
+ }
+
+ private boolean isTransportException(InvocationTargetException e) {
+ return e.getTargetException() instanceof JGitInternalException
+ && e.getTargetException().getCause() instanceof TransportException;
+ }
+
+ private TransportException getTransportException(InvocationTargetException e) {
+ if (isTransportException(e)) {
+ return (TransportException) ((JGitInternalException)
e.getTargetException()).getCause();
+ }
+ return null;
+ }
+
+ /**
+ * A workspace job that will create a new project or enable the selected
+ * project to be used with OpenShift.
+ */
+ private class ImportJob extends WorkspaceJob {
+
+ private DelegatingProgressMonitor delegatingMonitor;
+
+ public ImportJob(DelegatingProgressMonitor delegatingMonitor) {
+ super("Importing project to workspace...");
+ this.delegatingMonitor = delegatingMonitor;
+ }
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ try {
+ delegatingMonitor.add(monitor);
+
+ if (model.isNewProject()) {
+ model.importProject(delegatingMonitor);
+ } else {
+ if (!askForConfirmation(model.getApplicationName(), model.getProjectName())) {
+ return Status.CANCEL_STATUS;
+ }
+ model.configureUnsharedProject(delegatingMonitor);
+ }
+
+ return Status.OK_STATUS;
+ } catch (final WontOverwriteException e) {
+ openError("Project already present", e.getMessage());
+ return Status.CANCEL_STATUS;
+ } catch (final ImportFailedException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import maven project {0}.", e,
+ model.getProjectName());
+ } catch (IOException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not copy openshift configuration files to project {0}", e,
+ model.getProjectName());
+ } catch (OpenShiftException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import project to the workspace.", e);
+ } catch (URISyntaxException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "The url of the remote git repository is not valid", e);
+ } catch (InvocationTargetException e) {
+ if (isTransportException(e)) {
+ TransportException te = getTransportException(e);
+ return OpenShiftUIActivator
+ .createErrorStatus(
+ "Could not clone the repository. Authentication failed.\n"
+ + " Please make sure that you added your private key to the ssh
preferences.",
+ te);
+ } else {
+ return OpenShiftUIActivator.createErrorStatus(
+ "An exception occurred while creating local git repository.", e);
+ }
+ } catch (Exception e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not import project to the workspace.", e);
+ } finally {
+ delegatingMonitor.done();
+ }
+ }
+ }
+
+ private void openError(final String title, final String message) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(getShell(), title, message);
+ }
+ });
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizard.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizardModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizardModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+
+
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+public class ImportExistingApplicationWizardModel extends
AbstractOpenShiftApplicationWizardModel {
+
+ public ImportExistingApplicationWizardModel() {
+ dataModel.put(NEW_PROJECT, false);
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportExistingApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPage.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPage.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,313 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.ISWTObservableValue;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.fieldassist.AutoCompleteField;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.IWizard;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.WorkingSetGroup;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.tools.common.ui.databinding.InvertingBooleanConverter;
+import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ */
+public class ProjectAndServerAdapterSettingsWizardPage extends
AbstractOpenShiftWizardPage {
+
+ public static final String PREF_CONTENTASSISTKEY = "prefContentAssistKey";
+
+ private ProjectAndServerAdapterSettingsWizardPageModel pageModel;
+
+ private Text existingProjectNameText = null;
+
+ public ProjectAndServerAdapterSettingsWizardPage(IWizard wizard,
AbstractOpenShiftApplicationWizardModel wizardModel) {
+ super("Project configuration",
+ "Configure your project and server adapter settings, then click 'next'
or 'finish'.",
+ "Project configuration", wizard);
+ this.pageModel = new ProjectAndServerAdapterSettingsWizardPageModel(wizardModel);
+ }
+
+ @Override
+ protected void doCreateControls(Composite container, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
+ createProjectGroup(container, dbc);
+ createServerAdapterGroup(container, dbc);
+ createWorkingSetGroup(container, dbc);
+ }
+
+
+
+ private Composite createProjectGroup(Composite parent, DataBindingContext dbc) {
+ Composite projectGroup = new Composite(parent, SWT.NONE);
+ // projectGroup.setText("Project");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER).grab(true, false)
+ .applyTo(projectGroup);
+ GridLayoutFactory.fillDefaults().numColumns(5).margins(6, 6).applyTo(projectGroup);
+
+ // new project radio button
+ Button newProjectRadioBtn = new Button(projectGroup, SWT.RADIO);
+ newProjectRadioBtn.setText("Create a new project");
+ newProjectRadioBtn.setToolTipText("The project will have the name of the OpenShift
application");
+ newProjectRadioBtn.setFocus();
+ GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(false,
false)
+ .applyTo(newProjectRadioBtn);
+ final IObservableValue newProjectObservable = BeanProperties.value(
+ ProjectAndServerAdapterSettingsWizardPageModel.PROPERTY_IS_NEW_PROJECT).observe(pageModel);
+ final ISWTObservableValue newProjectRadioBtnSelection = WidgetProperties.selection()
+ .observe(newProjectRadioBtn);
+ dbc.bindValue(newProjectRadioBtnSelection, newProjectObservable);
+
+ // existing project
+ Button existingProjectRadioBtn = new Button(projectGroup, SWT.RADIO);
+ existingProjectRadioBtn.setText("Use an existing project");
+ existingProjectRadioBtn
+ .setToolTipText("The OpenShift application code will be merged into the existing
project");
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(3, 1).grab(false,
false)
+ .applyTo(existingProjectRadioBtn);
+ final ISWTObservableValue existingProjectRadioBtnSelection =
WidgetProperties.selection().observe(
+ existingProjectRadioBtn);
+ ValueBindingBuilder.bind(existingProjectRadioBtnSelection).notUpdating(newProjectObservable)
+ .converting(new InvertingBooleanConverter()).in(dbc);
+ existingProjectNameText = new Text(projectGroup, SWT.BORDER);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false)
+ .applyTo(existingProjectNameText);
+ final IObservableValue projectNameModelObservable = BeanProperties.value(
+ ProjectAndServerAdapterSettingsWizardPageModel.PROPERTY_PROJECT_NAME).observe(pageModel);
+ final ISWTObservableValue existingProjectNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(
+ existingProjectNameText);
+ ValueBindingBuilder.bind(existingProjectNameTextObservable).to(projectNameModelObservable).in(dbc);
+ // disable the project name text when the model state is set to 'new project'
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(existingProjectNameText))
+ .notUpdating(newProjectObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+ // move focus to the project name text control when choosing the 'Use an existing
project' option.
+ existingProjectRadioBtn.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ existingProjectNameText.setFocus();
+ existingProjectNameText.selectAll();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ // let's provide content assist on the existing project name
+ ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP |
SWT.LEFT);
+ FieldDecoration contentProposalFieldIndicator =
FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ dec.setImage(contentProposalFieldIndicator.getImage());
+ dec.setDescriptionText("Auto-completion is enabled when you start typing a project
name.");
+ dec.setShowOnlyOnFocus(true);
+
+ AutoCompleteField adapter = new AutoCompleteField(
+ existingProjectNameText, new TextContentAdapter(),
+ new String [] {});
+
+ adapter.setProposals(getOpenProjectsInWorkspace());
+
+ Button browseProjectsButton = new Button(projectGroup, SWT.NONE);
+ browseProjectsButton.setText("Browse");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100,
SWT.DEFAULT).span(1, 1).grab(false, false)
+ .applyTo(browseProjectsButton);
+ browseProjectsButton.addSelectionListener(onBrowseProjects());
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseProjectsButton))
+ .notUpdating(newProjectObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+
+ final IObservableValue existingProjectValidityObservable = BeanProperties.value(
+ ProjectAndServerAdapterSettingsWizardPageModel.PROPERTY_EXISTING_PROJECT_VALIDITY).observe(pageModel);
+ final UseExistingOpenProjectValidator existingProjectValidator = new
UseExistingOpenProjectValidator(
+ existingProjectValidityObservable, existingProjectNameTextObservable);
+ dbc.addValidationStatusProvider(existingProjectValidator);
+ ControlDecorationSupport.create(existingProjectValidator, SWT.LEFT | SWT.TOP);
+
+ return projectGroup;
+ }
+
+ private String[] getOpenProjectsInWorkspace() {
+ List<String> projects = new ArrayList<String>();
+ for(IProject project: ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ if(project.exists() && project.isOpen()) {
+ projects.add(project.getName());
+ }
+ }
+ return projects.toArray(new String[projects.size()]);
+ }
+
+ /**
+ * Open a dialog box to select an open project when clicking on the 'Browse'
button.
+ *
+ * @return
+ */
+ private SelectionListener onBrowseProjects() {
+ return new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SelectExistingProjectDialog dialog = new
SelectExistingProjectDialog(pageModel.getApplicationName(),
+ getShell());
+ if (dialog.open() == Dialog.OK) {
+ Object selectedProject = dialog.getFirstResult();
+ if (selectedProject instanceof IProject) {
+ pageModel.setProjectName(((IProject) selectedProject).getName());
+ }
+ }
+ }
+
+ };
+ }
+
+ private Group createServerAdapterGroup(Composite container, DataBindingContext dbc) {
+ Group serverAdapterGroup = new Group(container, SWT.BORDER);
+ serverAdapterGroup.setText("Server Adapter");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER).grab(true, false)
+ .applyTo(serverAdapterGroup);
+ GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(serverAdapterGroup);
+
+ Composite c = new Composite(serverAdapterGroup, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(c);
+ GridLayoutFactory.fillDefaults().numColumns(3).spacing(12, 8).applyTo(c);
+
+ final Button serverAdapterCheckbox = new Button(c, SWT.CHECK);
+ serverAdapterCheckbox.setText("Create a new Server Adapter");
+ serverAdapterCheckbox
+ .setToolTipText("This Server Adapter will let you publish your local changes
onto OpenShift, right from your Eclipse workbench.");
+ GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true,
false)
+ .applyTo(serverAdapterCheckbox);
+ final IObservableValue serverAdapterCheckboxObservable =
WidgetProperties.selection().observe(
+ serverAdapterCheckbox);
+ final IObservableValue serverAdapterModelObservable = BeanProperties.value(
+ ProjectAndServerAdapterSettingsWizardPageModel.PROPERTY_CREATE_SERVER_ADAPTER).observe(pageModel);
+ ValueBindingBuilder.bind(serverAdapterCheckboxObservable).to(serverAdapterModelObservable).in(dbc);
+ return serverAdapterGroup;
+ }
+
+ private IServerType getServerTypeToCreate() {
+ return
ServerCore.findServerType("org.jboss.tools.openshift.express.openshift.server.type");
+ }
+
+
+ private WorkingSetGroup createWorkingSetGroup(Composite container, DataBindingContext
dbc) {
+ return new WorkingSetGroup(container, null, new String[] {
"org.eclipse.ui.resourceWorkingSetPage", //$NON-NLS-1$
+ "org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */});
+ }
+
+ /**
+ * Verify that if the 'use an existing project' option was chose, then the
project name actually matches an open
+ * project in the workspace.
+ */
+ // @Override
+ // protected void onPageWillGetDeactivated(Direction direction, PageChangingEvent event,
DataBindingContext dbc) {
+ // if (direction == Direction.BACKWARDS) {
+ // return;
+ // }
+ // if (!pageModel.isNewProject()) {
+ // try {
+ // final ArrayBlockingQueue<IStatus> queue = new
ArrayBlockingQueue<IStatus>(1);
+ // WizardUtils.runInWizard(new Job("Verifying existing project exists and is
open...") {
+ // @Override
+ // protected IStatus run(IProgressMonitor monitor) {
+ // IStatus status = pageModel.validateExistingProject();
+ // queue.offer(status);
+ // monitor.done();
+ // return Status.OK_STATUS;
+ // }
+ // }, new DelegatingProgressMonitor(), getContainer(), getDatabindingContext());
+ // final IStatus status = queue.poll(10, TimeUnit.SECONDS);
+ // event.doit = status.isOK();
+ // if (!event.doit) {
+ // existingProjectNameText.setFocus();
+ // existingProjectNameText.selectAll();
+ // }
+ // } catch (Exception ex) {
+ // event.doit = false;
+ // } finally {
+ // }
+ //
+ // }
+ // }
+
+ class UseExistingOpenProjectValidator extends MultiValidator {
+
+ private final IObservableValue existingProjectValidityObservable;
+
+ private final IObservableValue existingProjectNameTextObservable;
+
+ public UseExistingOpenProjectValidator(IObservableValue
existingProjectValidityObservable,
+ IObservableValue existingProjectNameTextObservable) {
+ this.existingProjectValidityObservable = existingProjectValidityObservable;
+ this.existingProjectNameTextObservable = existingProjectNameTextObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final IStatus existingProjectValidityStatus = (IStatus)
existingProjectValidityObservable.getValue();
+
+ if (existingProjectValidityStatus != null) {
+ final IStatus existingProjectValidity = pageModel.getExistingProjectValidity();
+ return existingProjectValidity;
+ }
+ return ValidationStatus.ok();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ */
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ //targets.add(existingProjectNameTextObservable);
+ return targets;
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage#onPageActivated(org.eclipse.core.databinding.DataBindingContext)
+ */
+ @Override
+ protected void onPageActivated(DataBindingContext dbc) {
+ pageModel.validateExistingProject();
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPageModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+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.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author Andr� Dietisheim
+ * @author Xavier Coulon
+ *
+ */
+public class ProjectAndServerAdapterSettingsWizardPageModel extends ObservableUIPojo {
+
+ /** whether this is a new project or not. */
+ public static final String PROPERTY_IS_NEW_PROJECT = "newProject";
+
+ /** The project name, whether it is a new one or not. */
+ public static final String PROPERTY_PROJECT_NAME = "projectName";
+
+ /** whether this a server adapter should be created, or not. */
+ public static final String PROPERTY_CREATE_SERVER_ADAPTER =
"createServerAdapter";
+
+ /** Whether the existing project is a valid one or not. */
+ public static final String PROPERTY_EXISTING_PROJECT_VALIDITY =
"existingProjectValidity";
+
+ private AbstractOpenShiftApplicationWizardModel wizardModel;
+
+ private IStatus existingProjectValidity;
+
+ public
ProjectAndServerAdapterSettingsWizardPageModel(AbstractOpenShiftApplicationWizardModel
wizardModel) {
+ this.wizardModel = wizardModel;
+ setNewProject(true);
+ }
+
+ public void setNewProject(boolean newProject) {
+ firePropertyChange(PROPERTY_IS_NEW_PROJECT, wizardModel.isNewProject(),
wizardModel.setNewProject(newProject));
+ validateExistingProject();
+ }
+
+ public boolean isNewProject() {
+ return wizardModel.isNewProject();
+ }
+
+ public void setCreateServerAdapter(boolean createServerAdapter) {
+ firePropertyChange(PROPERTY_CREATE_SERVER_ADAPTER,
wizardModel.isCreateServerAdapter(),
+ wizardModel.setCreateServerAdapter(createServerAdapter));
+ }
+
+ public boolean isCreateServerAdapter() {
+ return wizardModel.isCreateServerAdapter();
+ }
+
+ public void setProjectName(String projectName) {
+ firePropertyChange(PROPERTY_PROJECT_NAME, wizardModel.getProjectName(),
wizardModel.setProjectName(projectName));
+ validateExistingProject();
+ }
+
+ public String getProjectName() {
+ return wizardModel.getProjectName();
+ }
+
+ public String getApplicationName() {
+ return wizardModel.getApplicationName();
+ }
+
+ public IStatus validateExistingProject() {
+ IStatus status = Status.OK_STATUS;
+ // skip the validation if the user wants to create a new project. The name and state of
the existing project do
+ // not matter...
+ final String applicationName = getApplicationName();
+ if (isNewProject() && applicationName != null) {
+ final IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(applicationName);
+ if(project.exists()) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "A project
named '" + applicationName + "' already exists in the
workspace.");
+ }
+ } else {
+ final String projectName = wizardModel.getProjectName();
+ if (projectName == null || projectName.isEmpty()) {
+ status = new Status(IStatus.CANCEL, OpenShiftUIActivator.PLUGIN_ID,
+ "Select an open project in the workspace.");
+ } else {
+ final IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (!project.exists()) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "The project
does not exist.");
+ } else if (!project.isOpen()) {
+ status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "The project
is not open.");
+ }
+ }
+ }
+ setExistingProjectValidity(status);
+ return status;
+ }
+
+ public void setExistingProjectValidity(IStatus status) {
+ firePropertyChange(PROPERTY_EXISTING_PROJECT_VALIDITY, this.existingProjectValidity,
+ this.existingProjectValidity = status);
+ }
+
+ public IStatus getExistingProjectValidity() {
+ return this.existingProjectValidity;
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ProjectAndServerAdapterSettingsWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizard.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizard.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -38,13 +38,17 @@
import org.jboss.tools.openshift.express.internal.ui.WontOverwriteException;
import org.jboss.tools.openshift.express.internal.ui.wizard.AdapterWizardPage;
import org.jboss.tools.openshift.express.internal.ui.wizard.ApplicationWizardPage;
+import org.jboss.tools.openshift.express.internal.ui.wizard.CreateNewApplicationWizard;
import org.jboss.tools.openshift.express.internal.ui.wizard.CredentialsWizardPage;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.ImportExistingApplicationWizard;
import com.openshift.express.client.OpenShiftException;
/**
* @author André Dietisheim
+ * @Deprecated: see the {@link CreateNewApplicationWizard} and the {@link
ImportExistingApplicationWizard}
*/
+@Deprecated
public class ImportProjectWizard extends Wizard implements INewWizard {
private ImportProjectWizardModel model;
@@ -93,7 +97,7 @@
@Override
public void addPages() {
this.model = new ImportProjectWizardModel();
- addPage(new CredentialsWizardPage(this, model));
+ //addPage(new CredentialsWizardPage(this, model));
addPage(new ApplicationWizardPage(this, model));
addPage(new AdapterWizardPage(this, model));
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -27,6 +27,8 @@
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.egit.core.EGitUtils;
import org.jboss.tools.openshift.express.internal.ui.wizard.AdapterWizardPageModel;
+import org.jboss.tools.openshift.express.internal.ui.wizard.CreateNewApplicationWizard;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.ImportExistingApplicationWizard;
import com.openshift.express.client.IApplication;
import com.openshift.express.client.ICartridge;
@@ -35,7 +37,9 @@
/**
* @author André Dietisheim <adietish(a)redhat.com>
+ * @Deprecated: see the {@link CreateNewApplicationWizardModel} and the {@link
ImportExistingApplicationWizardModel}
*/
+@Deprecated
public class ImportProjectWizardModel extends ObservableUIPojo {
private HashMap<String, Object> dataModel = new HashMap<String, Object>();
@@ -153,7 +157,7 @@
throws OpenShiftException {
Assert.isTrue(importedProjects.size() > 0);
IProject project = importedProjects.get(0);
- new ServerAdapterFactory().create(project, this, monitor);
+ //new ServerAdapterFactory().create(project, this, monitor);
}
public File getRepositoryFile() {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java 2012-01-24
16:37:04 UTC (rev 38107)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java 2012-01-24
16:53:11 UTC (rev 38108)
@@ -34,6 +34,7 @@
import org.eclipse.wst.server.core.internal.Server;
import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftApplicationWizardModel;
import com.openshift.express.client.IApplication;
import com.openshift.express.client.IUser;
@@ -42,14 +43,14 @@
/**
* @author André Dietisheim <adietish(a)redhat.com>
*/
-class ServerAdapterFactory {
+public class ServerAdapterFactory {
public ServerAdapterFactory() {
}
- public void create(IProject project, ImportProjectWizardModel model, IProgressMonitor
monitor) throws OpenShiftException {
- createServerAdapter(project, model.getServerType(), model.getRuntime(),
model.getMode(),
- model.getApplication(), model.getUser(), model.getRemoteName(), monitor);
+ public void create(IProject project, AbstractOpenShiftApplicationWizardModel
wizardModel, IProgressMonitor monitor) throws OpenShiftException {
+ createServerAdapter(project, wizardModel.getServerType(), wizardModel.getRuntime(),
wizardModel.getMode(),
+ wizardModel.getApplication(), wizardModel.getUser(), wizardModel.getRemoteName(),
monitor);
}
public void create(IProject project, IServerType serverType, IRuntime runtime, String
mode,