Author: adietish
Date: 2012-05-11 11:08:22 -0400 (Fri, 11 May 2012)
New Revision: 40953
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/CreateApplicationOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeListener.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbeddedCartridgeWizardStrategy.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.client/openshift-java-client-2.0.0-SNAPSHOT.jar
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/ApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
Log:
[JBIDE-11835][JBIDE-10852] unified cartridge embedding. fixed bug where not being able to
remove mysql / add postgres (and vice-versa)
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.client/openshift-java-client-2.0.0-SNAPSHOT.jar
===================================================================
(Binary files differ)
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/CreateApplicationOperation.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/CreateApplicationOperation.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/CreateApplicationOperation.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.core;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
+import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+
+import com.openshift.client.ApplicationScale;
+import com.openshift.client.IApplication;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IGearProfile;
+import com.openshift.client.OpenShiftApplicationNotAvailableException;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class CreateApplicationOperation {
+
+ private static final int APP_CREATION_TIMEOUT = 180;
+ private UserDelegate user;
+
+ public CreateApplicationOperation(UserDelegate user) {
+ this.user = user;
+ }
+
+ public IApplication execute(final String name, final ICartridge cartridge,
+ final ApplicationScale scale, final IGearProfile gearProfile, final IProgressMonitor
monitor)
+ throws OpenShiftApplicationNotAvailableException, OpenShiftException {
+ if (user == null) {
+ throw new OpenShiftException("Could not create application, have no valid user
credentials");
+ }
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ try {
+ FutureTask<IApplication> future = new FutureTask<IApplication>(
+ new Callable<IApplication>() {
+ @Override
+ public IApplication call() throws Exception {
+ monitor.setTaskName("Creating application \"" + name +
"\"...");
+ Logger.debug("creating application...");
+ final IApplication application =
+ user.createApplication(name, cartridge, scale, gearProfile);
+ monitor.beginTask(
+ "Waiting for application to be reachable...",
IProgressMonitor.UNKNOWN);
+ Logger.debug("Waiting for application to be reachable...");
+ waitForAccessible(application, monitor);
+ return application;
+ }
+ });
+ executor.execute(future);
+ while (!future.isDone()) {
+ if (monitor.isCanceled()) {
+ throw new OpenShiftException("Operation was cancelled by user.");
+ }
+ Thread.sleep(1000);
+ }
+ final IApplication application = future.get();
+ return application;
+ } catch (Exception e) { // InterruptedException and ExecutionException
+ Throwable cause = e.getCause() != null ? e.getCause() : e;
+ Logger.error("Failed to create application", cause);
+ throw new OpenShiftException("Failed to create application: {0}",
cause.getMessage());
+ } finally {
+ executor.shutdown();
+ }
+ }
+
+ 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()));
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/CreateApplicationOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.core;
+
+import java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.list.ListDiff;
+import org.eclipse.core.databinding.observable.list.ListDiffEntry;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import com.openshift.client.IApplication;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.IEmbeddedCartridge;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgesOperation {
+
+ private IApplication application;
+
+ public EmbedCartridgesOperation(IApplication application) {
+ this.application = application;
+ }
+
+ public List<IEmbeddedCartridge> execute(final List<IEmbeddableCartridge>
enabledCartridges, final IProgressMonitor monitor) throws SocketTimeoutException,
OpenShiftException {
+ if (enabledCartridges == null) {
+ return Collections.emptyList();
+ }
+ List<IEmbeddableCartridge> cartridgesToAdd = new
ArrayList<IEmbeddableCartridge>();
+ List<IEmbeddableCartridge> cartridgesToRemove = new
ArrayList<IEmbeddableCartridge>();
+ computeAdditionsAndRemovals(
+ cartridgesToAdd,
+ cartridgesToRemove,
+ enabledCartridges,
+ application.getEmbeddedCartridges());
+ removeEmbeddedCartridges(cartridgesToRemove, application);
+ final List<IEmbeddedCartridge> addedCartridges =
addEmbeddedCartridges(cartridgesToAdd, application);
+ return addedCartridges;
+
+ }
+
+ private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
cartridgesToRemove, final IApplication application) throws OpenShiftException,
+ SocketTimeoutException {
+ if (cartridgesToRemove.isEmpty()) {
+ return;
+ }
+ // Collections.sort(removedCartridges, new CartridgeComparator());
+ for (IEmbeddableCartridge cartridgeToRemove : cartridgesToRemove) {
+ final IEmbeddedCartridge embeddedCartridge =
application.getEmbeddedCartridge(cartridgeToRemove);
+ if (embeddedCartridge != null) {
+ embeddedCartridge.destroy();
+ }
+ }
+ }
+
+ private List<IEmbeddedCartridge>
addEmbeddedCartridges(List<IEmbeddableCartridge> cartridgesToAdd, final IApplication
application)
+ throws OpenShiftException, SocketTimeoutException {
+ if (cartridgesToAdd.isEmpty()) {
+ return Collections.emptyList();
+ }
+ // Collections.sort(addedCartridges, new CartridgeComparator());
+ return application.addEmbeddableCartridges(cartridgesToAdd);
+ }
+
+ private void computeAdditionsAndRemovals(List<IEmbeddableCartridge>
addedCartridges,
+ List<IEmbeddableCartridge> removedCartridges, List<IEmbeddableCartridge>
selectedCartridges,
+ List<IEmbeddedCartridge> embeddedCartidges)
+ throws OpenShiftException, SocketTimeoutException {
+ ListDiff listDiff = Diffs.computeListDiff(embeddedCartidges, selectedCartridges);
+ for (ListDiffEntry entry : listDiff.getDifferences()) {
+ if (entry.isAddition()) {
+ addedCartridges.add((IEmbeddableCartridge) entry.getElement());
+ } else {
+ removedCartridges.add((IEmbeddableCartridge) entry.getElement());
+ }
+ }
+ Collections.sort(addedCartridges, new CartridgeComparator());
+ Collections.sort(removedCartridges, new CartridgeComparator());
+ }
+
+ private static class CartridgeComparator implements
Comparator<IEmbeddableCartridge> {
+
+ @Override
+ public int compare(IEmbeddableCartridge thisCartridge, IEmbeddableCartridge
thatCartridge) {
+ // mysql has to be added/removed before phpmyadmin
+ if (thisCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
+ return -1;
+ } else if (thatCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
+ return 1;
+ } else if (thisCartridge.equals(IEmbeddableCartridge.POSTGRESQL_84)) {
+ return -1;
+ } else if (thatCartridge.equals(IEmbeddableCartridge.POSTGRESQL_84)) {
+ return 1;
+ } else if (thisCartridge.equals(IEmbeddableCartridge.MONGODB_20)) {
+ return -1;
+ } else if (thatCartridge.equals(IEmbeddableCartridge.MONGODB_20)) {
+ return 1;
+ }
+ return 0;
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.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/ApplicationConfigurationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -49,10 +49,8 @@
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;
@@ -111,7 +109,6 @@
private Group newAppEmbeddableCartridgesGroup;
private Button checkAllButton;
private Button uncheckAllButton;
- private EmbeddedCartridgeWizardStrategy embeddedCartridgeWizardStrategy;
public ApplicationConfigurationWizardPage(IWizard wizard,
OpenShiftExpressApplicationWizardModel wizardModel) {
super("Setup OpenShift Application",
@@ -136,8 +133,6 @@
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL,
SWT.FILL).applyTo(container);
createApplicationSelectionGroup(container, dbc);
createApplicationConfigurationGroup(container, dbc);
-
- this.embeddedCartridgeWizardStrategy = new EmbeddedCartridgeWizardStrategy(viewer,
this, pageModel);
}
private Composite createApplicationSelectionGroup(Composite container,
DataBindingContext dbc) {
@@ -338,6 +333,7 @@
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(1,
2).hint(400, 250)
.applyTo(tableContainer);
this.viewer = createTable(tableContainer);
+ viewer.addCheckStateListener(new EmbedCartridgeListener(viewer, pageModel, this));
dbc.bindSet(ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
BeanProperties.set(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
.observe(pageModel));
@@ -432,7 +428,6 @@
CheckboxTableViewer viewer = new CheckboxTableViewer(table);
viewer.setComparer(new EqualityComparer());
viewer.setContentProvider(new ArrayContentProvider());
- viewer.addCheckStateListener(onCartridgeChecked());
createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
@Override
@@ -452,28 +447,6 @@
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()) {
- embeddedCartridgeWizardStrategy.addCartridge(cartridge);
- } else {
- embeddedCartridgeWizardStrategy.removeCartridge(cartridge);
- }
- } catch (OpenShiftException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- } catch (SocketTimeoutException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- }
- }
- };
- }
-
-
private SelectionListener onCheckAll() {
return new SelectionAdapter() {
Modified:
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 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -19,6 +19,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.core.CreateApplicationOperation;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
@@ -35,10 +36,11 @@
* @author Xavier Coulon
*
*/
-public class ApplicationConfigurationWizardPageModel extends ObservableUIPojo {
+public class ApplicationConfigurationWizardPageModel extends ObservableUIPojo implements
+ IEmbedCartridgesWizardPageModel {
public static final String PROPERTY_USE_EXISTING_APPLICATION =
"useExistingApplication";
- public static final String PROPERTY_APPLICATION_SCALE = "applicationScale";
+ public static final String PROPERTY_APPLICATION_SCALE = "scale";
public static final String PROPERTY_EXISTING_APPLICATION_NAME =
"existingApplicationName";
public static final String PROPERTY_CARTRIDGES = "cartridges";
public static final String PROPERTY_EMBEDDED_CARTRIDGES =
"embeddedCartridges";
@@ -50,7 +52,6 @@
public static final String PROPERTY_EXISTING_APPLICATIONS_LOADED =
"existingApplicationsLoaded";
public static final String PROPERTY_SCALABLE_APPLICATION =
"scalableApplication";
public static final String PROPERTY_GEAR_PROFILES = "gearProfiles";
-
private final OpenShiftExpressApplicationWizardModel wizardModel;
@@ -114,18 +115,17 @@
, wizardModel.isUseExistingApplication()
, wizardModel.setUseExistingApplication(useExistingApplication));
}
-
- public ApplicationScale getApplicationScale() {
+
+ public ApplicationScale getScale() {
return wizardModel.getApplicationScale();
}
- public void setApplicationScale(ApplicationScale scale) {
+ public void setScale(ApplicationScale scale) {
firePropertyChange(PROPERTY_APPLICATION_SCALE
, wizardModel.getApplicationScale()
, wizardModel.setApplicationScale(scale));
}
-
protected void setUseExistingApplication(IApplication application) {
setUseExistingApplication(application != null);
}
@@ -141,7 +141,7 @@
*
* @param applicationName
* @throws OpenShiftException
- * @throws SocketTimeoutException
+ * @throws SocketTimeoutException
*
* @see #doSetExistingApplication(IApplication)
*/
@@ -209,25 +209,24 @@
firePropertyChange(PROPERTY_CARTRIDGES, this.cartridges, this.cartridges =
cartridges);
}
-
public List<ICartridge> getCartridges() {
return cartridges;
}
-
+
public ICartridge getCartridgeByName(String name) {
List<ICartridge> cartridges = getCartridges();
if (cartridges == null) {
return null;
}
-
- ICartridge matchingCartridge = null;
+
+ ICartridge matchingCartridge = null;
for (ICartridge cartridge : cartridges) {
if (name.equals(cartridge.getName())) {
matchingCartridge = cartridge;
break;
}
}
-
+
return matchingCartridge;
}
@@ -237,18 +236,17 @@
public void loadGearProfiles() throws OpenShiftException, SocketTimeoutException {
setGearProfiles(getUser().getDefaultDomain().getAvailableGearProfiles());
- //refreshSelectedCartridge();
+ // refreshSelectedCartridge();
}
-
-
+
public void setGearProfiles(List<IGearProfile> gearProfiles) {
firePropertyChange(PROPERTY_GEAR_PROFILES, this.gearProfiles, this.gearProfiles =
gearProfiles);
}
-
+
public List<IGearProfile> getGearProfiles() {
return gearProfiles;
}
-
+
public IGearProfile getSelectedGearProfile() {
return wizardModel.getApplicationGearProfile();
}
@@ -264,15 +262,15 @@
if (gearProfiles == null) {
return null;
}
-
- IGearProfile matchingGearProfile = null;
+
+ IGearProfile matchingGearProfile = null;
for (IGearProfile gearProfile : gearProfiles) {
if (name.equals(gearProfile.getName())) {
matchingGearProfile = gearProfile;
break;
}
}
-
+
return matchingGearProfile;
}
@@ -308,7 +306,7 @@
*
* @param application
* @throws OpenShiftException
- * @throws SocketTimeoutException
+ * @throws SocketTimeoutException
*
* @see #setExistingApplicationName(String)
* @see #setApplicationName(IApplication)
@@ -329,7 +327,7 @@
*
* @param application
* @throws OpenShiftException
- * @throws SocketTimeoutException
+ * @throws SocketTimeoutException
*
* @see #setApplicationName(IApplication)
* @see #setSelectedCartridge(IApplication)
@@ -342,7 +340,7 @@
setSelectedCartridge(application.getCartridge());
setSelectedEmbeddableCartridges(new
HashSet<IEmbeddableCartridge>(application.getEmbeddedCartridges()));
setSelectedGearProfile(application.getGearProfile());
- setApplicationScale(application.getApplicationScale());
+ setScale(application.getApplicationScale());
wizardModel.setApplication(application);
}
}
@@ -378,14 +376,17 @@
return embeddedCartridges;
}
+ @Override
public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException {
return wizardModel.getSelectedEmbeddableCartridges();
}
+ @Override
public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException {
getSelectedEmbeddableCartridges().add(cartridge);
}
+ @Override
public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException {
getSelectedEmbeddableCartridges().remove(cartridge);
}
@@ -396,6 +397,7 @@
wizardModel.setSelectedEmbeddableCartridges(selectedEmbeddableCartridges));
}
+ @Override
public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
return getUser().hasApplicationOfType(cartridge);
}
@@ -409,7 +411,14 @@
}
public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
- return wizardModel.createApplication(name, ICartridge.JENKINS_14,
ApplicationScale.NO_SCALE, IGearProfile.SMALL, monitor);
+ IApplication application =
+ new CreateApplicationOperation(getUser()).execute(
+ name,
+ ICartridge.JENKINS_14,
+ ApplicationScale.NO_SCALE,
+ IGearProfile.SMALL,
+ monitor);
+ return application;
}
}
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-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2012 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,
@@ -10,107 +10,29 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.net.SocketTimeoutException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
-import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
-import com.openshift.client.ApplicationScale;
import com.openshift.client.IApplication;
-import com.openshift.client.ICartridge;
-import com.openshift.client.IGearProfile;
-import com.openshift.client.OpenShiftApplicationNotAvailableException;
-import com.openshift.client.OpenShiftException;
/**
* @author André Dietisheim
*/
public class ApplicationWizardModel extends ObservableUIPojo {
- public static final String PROPERTY_APPLICATION = "application";
-
- /**
- * Timeout in seconds when trying to contact an application after it had
- * been created.
- */
- private static final int APP_CREATION_TIMEOUT = 10;
-
- private UserDelegate user;
private IApplication application;
- private String name;
- private ICartridge cartridge;
- private ApplicationScale scale;
- private IGearProfile gearProfile;
+ private UserDelegate user;
- public ApplicationWizardModel(UserDelegate user) {
- this(null, user);
- }
-
public ApplicationWizardModel(IApplication application, UserDelegate user) {
this.application = application;
this.user = user;
}
- public UserDelegate getUser() {
- return user;
- }
-
- public String setName(String name) {
- return this.name = name;
- }
-
- /**
- * @param scale the scale to set
- */
- public final void setScale(ApplicationScale scale) {
- this.scale = scale;
- }
-
- /**
- * @param gearProfile the gearProfile to set
- */
- public final void setGearProfile(IGearProfile gearProfile) {
- this.gearProfile = gearProfile;
- }
-
- public void setCartridge(ICartridge cartridge) {
- this.cartridge = cartridge;
- }
-
-
- public void setApplication(IApplication application) {
- firePropertyChange(PROPERTY_APPLICATION, this.application, this.application =
application);
- }
-
public IApplication getApplication() {
return application;
}
- public void createApplication(IProgressMonitor monitor) throws OpenShiftException,
SocketTimeoutException {
- IApplication application = createApplication(this.name, this.cartridge, this.scale ,
this.gearProfile, monitor);
- setApplication(application);
+ public UserDelegate getUser() {
+ return user;
}
- public IApplication createApplication(final String name, final ICartridge cartridge,
final ApplicationScale scale, final IGearProfile gearProfile, IProgressMonitor monitor)
throws OpenShiftException, SocketTimeoutException {
-// monitor.subTask("creating application...");
- IApplication application = getUser().createApplication(name, cartridge, scale,
gearProfile);
- waitForAccessible(application, monitor);
- return application;
- }
-
- public boolean hasApplication(String name) throws OpenShiftException,
SocketTimeoutException {
- return user.hasApplication(name);
- }
-
- 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()));
- }
- }
-
}
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeListener.java
(from rev 40920,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbeddedCartridgeWizardStrategy.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeListener.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeListener.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -0,0 +1,299 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.net.SocketTimeoutException;
+
+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.Dialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+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 com.openshift.client.IApplication;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * A UI strategy that is able to add and remove embedded cartridges while
+ * fullfilling requirements and resolving conflicts (ex. mutual exclusivity
+ * etc.)
+ *
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgeListener implements ICheckStateListener {
+
+ private CheckboxTableViewer viewer;
+ private IEmbedCartridgesWizardPageModel pageModel;
+ private IWizardPage wizardPage;
+
+ public EmbedCartridgeListener(CheckboxTableViewer viewer,
+ IEmbedCartridgesWizardPageModel pageModel, IWizardPage wizardPage) {
+ this.viewer = viewer;
+ this.wizardPage = wizardPage;
+ this.pageModel = pageModel;
+ }
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ try {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ if (event.getChecked()) {
+ addCartridge(cartridge);
+ } else {
+ removeCartridge(cartridge);
+ }
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
+ } catch (SocketTimeoutException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
+ }
+ }
+
+ private void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
+ if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
+ addPhpMyAdmin();
+ } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
+ addJenkins(cartridge);
+ } else if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
+ addMySql();
+ } else if (IEmbeddableCartridge.POSTGRESQL_84.equals(cartridge)) {
+ addPostgreSql();
+ } else if (IEmbeddableCartridge.ROCKMONGO_11.equals(cartridge)) {
+ addRockMongo();
+ } else if (IEmbeddableCartridge._10GEN_MMS_AGENT_01.equals(cartridge)) {
+ add10gen();
+ } else {
+ pageModel.selectEmbeddedCartridges(cartridge);
+ }
+ }
+
+ private void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
+ if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
+ removeMySQL();
+ } else if (IEmbeddableCartridge.MONGODB_20.equals(cartridge)) {
+ removeMongoDb();
+ } else {
+ pageModel.unselectEmbeddedCartridges(cartridge);
+ }
+ }
+
+ private void addJenkins(final IEmbeddableCartridge cartridge) throws
OpenShiftException,
+ SocketTimeoutException {
+ if (pageModel.hasApplicationOfType(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());
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ private void addPhpMyAdmin() throws OpenShiftException, SocketTimeoutException {
+ if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
+ if (MessageDialog.openQuestion(getShell(), "Embed phpMyAdmin Cartridge",
+ "To embed phpMyAdmin, you'd also have to embed MySQL. \n\nAlso embed
MySQL?")) {
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+ private void addMySql()
+ throws OpenShiftException, SocketTimeoutException {
+ if (viewer.getChecked(IEmbeddableCartridge.POSTGRESQL_84)) {
+ if (MessageDialog
+ .openQuestion(getShell(), "Remove PostgreSQL Cartridge",
+ "MySQL and PostgreSQL are mutually exclusive. To embed MySQL, you have to
remove PostgreSQL. \n\nRemove PostgreSQL?")) {
+ viewer.setChecked(IEmbeddableCartridge.POSTGRESQL_84, false);
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, false);
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ }
+
+ private void addPostgreSql()
+ throws OpenShiftException, SocketTimeoutException {
+ if (viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
+ if (MessageDialog
+ .openQuestion(getShell(), "Remove MySQL Cartridge",
+ "MySQL and PostgreSQL are mutually exclusive. To embed PostgreSQL, you have
to remove MySQL.\n\nRemove MySQL?")) {
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, false);
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.POSTGRESQL_84, false);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
+ }
+ }
+
+ private void removeMySQL() throws OpenShiftException, SocketTimeoutException {
+ 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.\n\nRemove phpMyAdmin and MySQL?")) {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
+ }
+ } else {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ }
+
+ private void addRockMongo() throws OpenShiftException, SocketTimeoutException {
+ if (!viewer.getChecked(IEmbeddableCartridge.MONGODB_20)) {
+ if (MessageDialog.openQuestion(getShell(), "Embed MongoDB Cartridge",
+ "To embed RockMongo, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
+ viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.MONGODB_20, false);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+ private void removeMongoDb() throws OpenShiftException, SocketTimeoutException {
+ if (viewer.getChecked(IEmbeddableCartridge.ROCKMONGO_11)) {
+ if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
+ "If you remove the MongoDB cartridge, you'd also have to remove
RockMongo.")) {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
+ viewer.setChecked(IEmbeddableCartridge.ROCKMONGO_11, false);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
+ }
+ } else {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
+ }
+ }
+
+ private void add10gen() throws OpenShiftException, SocketTimeoutException {
+ if (!viewer.getChecked(IEmbeddableCartridge.MONGODB_20)) {
+ if (MessageDialog.openQuestion(getShell(), "Embed 10gen Cartridge",
+ "To embed 10gen cartridge, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
+ viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
+ } else {
+ viewer.setChecked(IEmbeddableCartridge.MONGODB_20, false);
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ viewer.setChecked(IEmbeddableCartridge._10GEN_MMS_AGENT_01, false);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+
+ private Shell getShell() {
+ return viewer.getControl().getShell();
+ }
+
+ private IWizardContainer getContainer() {
+ return wizardPage.getWizard().getContainer();
+ }
+
+ private void openLogDialog(final IApplication application) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ new CreationLogDialog(getShell(), application).open();
+ }
+ });
+ }
+
+ private static class JenkinsApplicationDialog extends InputDialog {
+
+ public JenkinsApplicationDialog(Shell shell) {
+ super(
+ shell,
+ "New Jenkins application",
+ "To embed Jenkins into your application, you first have to create a separate
Jenkins application. "
+ + "Please provide a name for this new Jenkins application (lower-case letters
and digits only):"
+ , 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";
+ }
+
+ if (!StringUtils.isAlphaNumeric(input)) {
+ return "The name may only contain lower-case letters and digits.";
+ }
+ return null;
+ }
+ }
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeListener.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/EmbedCartridgeWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2012 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,
@@ -22,19 +22,13 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-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;
@@ -44,14 +38,10 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
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 com.openshift.client.IApplication;
-import com.openshift.client.ICartridge;
import com.openshift.client.IEmbeddableCartridge;
import com.openshift.client.IEmbeddedCartridge;
import com.openshift.client.OpenShiftException;
@@ -61,13 +51,13 @@
*/
public class EmbedCartridgeWizardPage extends AbstractOpenShiftWizardPage {
- private EmbedCartridgeWizardPageModel model;
+ private EmbedCartridgeWizardPageModel pageModel;
private CheckboxTableViewer viewer;
public EmbedCartridgeWizardPage(ApplicationWizardModel wizardModel, IWizard wizard) {
super("Embed Cartridges", "Please select the cartridges to embed into
your application",
"EmbedCartridgePage", wizard);
- this.model = new EmbedCartridgeWizardPageModel(wizardModel);
+ this.pageModel = new EmbedCartridgeWizardPageModel(wizardModel);
}
@Override
@@ -85,8 +75,8 @@
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
- viewer.addCheckStateListener(onCartridgeChecked());
-
+ viewer.addCheckStateListener(new EmbedCartridgeListener(viewer, pageModel, this));
+
// hiding buttons for now:
https://issues.jboss.org/browse/JBIDE-10399
// Button checkAllButton = new Button(embedGroup, SWT.PUSH);
// checkAllButton.setText("Embed A&ll");
@@ -130,121 +120,6 @@
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 (IEmbeddedCartridge.PHPMYADMIN_34.equals(cartridge)) {
- addPhpMyAdminCartridge(cartridge);
- } else if (IEmbeddedCartridge.JENKINS_14.equals(cartridge)) {
- addJenkinsCartridge(cartridge);
- } else {
- addCartridge(cartridge);
- }
- } else {
- if (IEmbeddedCartridge.MYSQL_51.equals(cartridge)) {
- removeMySQLCartridge(cartridge);
- } else {
- removeCartridge(cartridge);
- }
- }
- } catch (OpenShiftException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- } catch (SocketTimeoutException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- }
- }
- };
- }
-
- private void addJenkinsCartridge(final IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException {
- if (model.hasApplication(ICartridge.JENKINS_14)) {
- model.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 = model.createJenkinsApplication(name, monitor);
- model.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, SocketTimeoutException {
- if (!viewer.getChecked(IEmbeddedCartridge.MYSQL_51)) {
- if (MessageDialog.openQuestion(getShell(), "Embed mysql cartridge",
- "To embed phpmyadmin, you'd also have to embed mysql.")) {
- model.getSelectedEmbeddableCartridges().add(IEmbeddedCartridge.MYSQL_51);
- model.getSelectedEmbeddableCartridges().add(cartridge);
- viewer.setChecked(IEmbeddedCartridge.MYSQL_51, true);
- } else {
- viewer.setChecked(cartridge, false);
- }
- } else {
- model.getSelectedEmbeddableCartridges().add(cartridge);
- }
- }
-
- private void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
- model.getSelectedEmbeddableCartridges().add(cartridge);
- }
-
- private void removeMySQLCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException {
- List<IEmbeddableCartridge> checkedCartridges =
model.getSelectedEmbeddableCartridges();
- if (viewer.getChecked(IEmbeddedCartridge.PHPMYADMIN_34)) {
- if (MessageDialog.openQuestion(getShell(), "Remove phpmyadmin cartridge",
- "If you remove the mysql cartridge, you'd also have to remove
phpmyadmin.")) {
- checkedCartridges.remove(IEmbeddedCartridge.PHPMYADMIN_34);
- checkedCartridges.remove(cartridge);
- viewer.setChecked(IEmbeddedCartridge.PHPMYADMIN_34, false);
- } else {
- viewer.setChecked(cartridge, true);
- }
- } else {
- checkedCartridges.remove(cartridge);
- }
- }
-
- private void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
- model.getSelectedEmbeddableCartridges().remove(cartridge);
- }
-
// private SelectionListener onCheckAll() {
// return new SelectionAdapter() {
//
@@ -282,8 +157,8 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- setViewerInput(model.loadEmbeddableCartridges());
- setViewerCheckedElements(model.getSelectedEmbeddableCartridges());
+ setViewerInput(pageModel.loadEmbeddableCartridges());
+ setViewerCheckedElements(pageModel.getSelectedEmbeddableCartridges());
return Status.OK_STATUS;
} catch (Exception e) {
clearViewer();
@@ -321,52 +196,29 @@
});
}
- 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;
- }
- }
- }
-
public boolean processCartridges() {
final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
try {
WizardUtils.runInWizard(
new Job(NLS.bind("Adding/Removing embedded cartridges for application
{0}...",
- model.getApplication().getName())) {
+ pageModel.getApplication().getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- List<IEmbeddedCartridge> addedCartridges = model.embedCartridges();
+ List<IEmbeddedCartridge> addedCartridges = pageModel.embedCartridges();
openLogDialog(addedCartridges);
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}",
- model.getApplication().getName()), e);
+ pageModel.getApplication().getName()), e);
} catch (SocketTimeoutException e) {
queue.offer(false);
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
NLS.bind("Could not embed cartridges to application {0}",
- model.getApplication().getName()), e);
+ pageModel.getApplication().getName()), e);
}
return Status.OK_STATUS;
}
@@ -392,16 +244,6 @@
});
}
- private void openLogDialog(final IApplication application) {
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- new CreationLogDialog(getShell(), application).open();
- }
- });
- }
-
/**
* Viewer element comparer based on #equals(). The default implementation in
* CheckboxTableViewer compares elements based on instance identity.
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2012 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,
@@ -12,15 +12,14 @@
import java.net.SocketTimeoutException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.list.ListDiff;
-import org.eclipse.core.databinding.observable.list.ListDiffEntry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.internal.core.CreateApplicationOperation;
+import org.jboss.tools.openshift.express.internal.core.EmbedCartridgesOperation;
import com.openshift.client.ApplicationScale;
import com.openshift.client.IApplication;
@@ -33,25 +32,22 @@
/**
* @author André Dietisheim
*/
-public class EmbedCartridgeWizardPageModel extends ObservableUIPojo {
+public class EmbedCartridgeWizardPageModel extends ObservableUIPojo implements
IEmbedCartridgesWizardPageModel {
- public static final String PROPERTY_APPLICATION = "application";
- public static final String PROPERTY_NAME = "name";
- public static final String PROPERTY_CARTRIDGES = "cartridges";
public static final String PROPERTY_EMBEDDABLE_CARTRIDGES =
"embeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
private ApplicationWizardModel wizardModel;
private List<IEmbeddableCartridge> embeddedCartridges = new
ArrayList<IEmbeddableCartridge>();
- private List<IEmbeddableCartridge> selectedCartridges;
+ private Set<IEmbeddableCartridge> selectedCartridges;
public EmbedCartridgeWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
}
- public void loadConfiguredEmbeddedCartridges() throws OpenShiftException,
SocketTimeoutException {
- selectedCartridges = new ArrayList<IEmbeddableCartridge>();
+ private void loadEmbeddedCartridges() throws OpenShiftException, SocketTimeoutException
{
+ selectedCartridges = new HashSet<IEmbeddableCartridge>();
IApplication application = wizardModel.getApplication();
if (application == null
|| application.getEmbeddedCartridges() == null) {
@@ -75,9 +71,10 @@
return embeddedCartridges;
}
- public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException, SocketTimeoutException {
+ public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges()
+ throws OpenShiftException, SocketTimeoutException {
if (selectedCartridges == null) {
- loadConfiguredEmbeddedCartridges();
+ loadEmbeddedCartridges();
}
return selectedCartridges;
}
@@ -90,76 +87,44 @@
return wizardModel.getApplication();
}
- public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException, SocketTimeoutException {
- return wizardModel.createApplication(name, ICartridge.JENKINS_14,
ApplicationScale.NO_SCALE, IGearProfile.SMALL, monitor);
+ @Override
+ public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException,
+ SocketTimeoutException {
+ getSelectedEmbeddableCartridges().add(cartridge);
}
-
+
+ @Override
+ public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException,
+ SocketTimeoutException {
+ getSelectedEmbeddableCartridges().remove(cartridge);
+ }
+
/**
* Embeds/removes the cartridges that were added/removed in this wizard
* page.
*
* @return the cartridges that were added (embedded).
* @throws OpenShiftException
- * @throws SocketTimeoutException
+ * @throws SocketTimeoutException
*/
public List<IEmbeddedCartridge> embedCartridges() throws OpenShiftException,
SocketTimeoutException {
- if (selectedCartridges == null) {
- return Collections.emptyList();
- }
- List<IEmbeddableCartridge> cartridgesToAdd = new
ArrayList<IEmbeddableCartridge>();
- List<IEmbeddableCartridge> cartridgesToRemove = new
ArrayList<IEmbeddableCartridge>();
- computeAdditionsAndRemovals(cartridgesToAdd, cartridgesToRemove, selectedCartridges);
- final List<IEmbeddedCartridge> addedCartridges =
addEmbeddedCartridges(cartridgesToAdd);
- removeEmbeddedCartridges(cartridgesToRemove);
- return addedCartridges;
+ return new EmbedCartridgesOperation(getApplication())
+ .execute(new ArrayList<IEmbeddableCartridge>(selectedCartridges), null);
}
- private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
cartridgesToRemove) throws OpenShiftException, SocketTimeoutException {
- if (cartridgesToRemove.isEmpty()) {
- return;
- }
- //Collections.sort(removedCartridges, new CartridgeComparator());
- for(IEmbeddableCartridge cartridgeToRemove : cartridgesToRemove) {
- final IEmbeddedCartridge embeddedCartridge =
getApplication().getEmbeddedCartridge(cartridgeToRemove);
- if(embeddedCartridge != null) {
- embeddedCartridge.destroy();
- }
- }
+ @Override
+ public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
+ return wizardModel.getUser().hasApplicationOfType(cartridge);
}
- private List<IEmbeddedCartridge>
addEmbeddedCartridges(List<IEmbeddableCartridge> cartridgesToAdd) throws
OpenShiftException, SocketTimeoutException {
- if (cartridgesToAdd.isEmpty()) {
- return Collections.emptyList();
- }
- //Collections.sort(addedCartridges, new CartridgeComparator());
- return getApplication().addEmbeddableCartridges(cartridgesToAdd);
+ public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
+ IApplication application =
+ new CreateApplicationOperation(wizardModel.getUser()).execute(
+ name,
+ ICartridge.JENKINS_14,
+ ApplicationScale.NO_SCALE,
+ IGearProfile.SMALL,
+ monitor);
+ return application;
}
-
- private void computeAdditionsAndRemovals(List<IEmbeddableCartridge>
addedCartridges,
- List<IEmbeddableCartridge> removedCartridges, List<IEmbeddableCartridge>
selectedCartridges)
- throws OpenShiftException, SocketTimeoutException {
- ListDiff listDiff = Diffs.computeListDiff(getApplication().getEmbeddedCartridges(),
selectedCartridges);
- for (ListDiffEntry entry : listDiff.getDifferences()) {
- if (entry.isAddition()) {
- addedCartridges.add((IEmbeddableCartridge) entry.getElement());
- } else {
- removedCartridges.add((IEmbeddableCartridge) entry.getElement());
- }
- }
- }
-
- private static class CartridgeComparator implements
Comparator<IEmbeddableCartridge> {
-
- @Override
- public int compare(IEmbeddableCartridge thisCartridge, IEmbeddableCartridge
thatCartridge) {
- // mysql has to be added/removed before phpmyadmin
- if (thisCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
- return -1;
- } else if (thatCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
- return 1;
- }
- return 0;
- }
- }
-
}
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbeddedCartridgeWizardStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbeddedCartridgeWizardStrategy.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbeddedCartridgeWizardStrategy.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -1,283 +0,0 @@
-/*******************************************************************************
- * 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.net.SocketTimeoutException;
-
-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.Dialog;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Shell;
-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 com.openshift.client.IApplication;
-import com.openshift.client.ICartridge;
-import com.openshift.client.IEmbeddableCartridge;
-import com.openshift.client.OpenShiftException;
-
-/**
- * A UI strategy that is able to add and remove embedded cartridges while
- * fullfilling requirements and resolving conflicts (ex. mutual exclusivity
- * etc.)
- *
- * @author Andre Dietisheim
- */
-public class EmbeddedCartridgeWizardStrategy {
-
- private CheckboxTableViewer viewer;
- private ApplicationConfigurationWizardPageModel pageModel;
- private IWizardPage wizardPage;
-
- public EmbeddedCartridgeWizardStrategy(CheckboxTableViewer viewer, IWizardPage
wizardPage,
- ApplicationConfigurationWizardPageModel pageModel) {
- this.viewer = viewer;
- this.wizardPage = wizardPage;
- this.pageModel = pageModel;
- }
-
- public void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
- if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
- addPhpMyAdmin();
- } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
- addJenkins(cartridge);
- } else if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
- addMySql();
- } else if (IEmbeddableCartridge.POSTGRESQL_84.equals(cartridge)) {
- addPostgreSql();
- } else if (IEmbeddableCartridge.ROCKMONGO_11.equals(cartridge)) {
- addRockMongo();
- } else if (IEmbeddableCartridge._10GEN_MMS_AGENT_01.equals(cartridge)) {
- add10gen();
- } else {
- pageModel.selectEmbeddedCartridges(cartridge);
- }
- }
-
- public void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException {
- if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
- removeMySQL();
- } else if (IEmbeddableCartridge.MONGODB_20.equals(cartridge)) {
- removeMongoDb();
- } else {
- pageModel.unselectEmbeddedCartridges(cartridge);
- }
- }
-
- private void addJenkins(final IEmbeddableCartridge cartridge) throws
OpenShiftException,
- SocketTimeoutException {
- if (pageModel.hasApplicationOfType(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());
- } catch (Exception e) {
- // ignore
- }
- }
-
- private void addPhpMyAdmin() throws OpenShiftException {
- if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
- if (MessageDialog.openQuestion(getShell(), "Embed phpMyAdmin Cartridge",
- "To embed phpMyAdmin, you'd also have to embed MySQL. \n\nAlso embed
MySQL?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, false);
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private void addMySql()
- throws OpenShiftException, SocketTimeoutException {
- if (viewer.getChecked(IEmbeddableCartridge.POSTGRESQL_84)) {
- if (MessageDialog
- .openQuestion(getShell(), "Remove PostgreSQL Cartridge",
- "MySQL and PostgreSQL are mutually exclusive. To embed MySQL, you have to
remove PostgreSQL. \n\nRemove PostgreSQL?")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- viewer.setChecked(IEmbeddableCartridge.POSTGRESQL_84, false);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, false);
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- }
-
- private void addPostgreSql()
- throws OpenShiftException, SocketTimeoutException {
- if (viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
- if (MessageDialog
- .openQuestion(getShell(), "Remove MySQL Cartridge",
- "MySQL and PostgreSQL are mutually exclusive. To embed PostgreSQL, you have
to remove MySQL. \n\nRemove MySQL?")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, false);
- } else {
- viewer.setChecked(IEmbeddableCartridge.POSTGRESQL_84, false);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- }
- }
-
- private void removeMySQL() throws OpenShiftException {
- 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.")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
- }
- } else {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- }
-
- private void addRockMongo() throws OpenShiftException {
- if (!viewer.getChecked(IEmbeddableCartridge.MONGODB_20)) {
- if (MessageDialog.openQuestion(getShell(), "Embed MongoDB Cartridge",
- "To embed RockMongo, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, false);
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- viewer.setChecked(IEmbeddableCartridge.ROCKMONGO_11, false);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private void removeMongoDb() throws OpenShiftException {
- if (viewer.getChecked(IEmbeddableCartridge.ROCKMONGO_11)) {
- if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
- "If you remove the MongoDB cartridge, you'd also have to remove
RockMongo.")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
- viewer.setChecked(IEmbeddableCartridge.ROCKMONGO_11, false);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
- }
- } else {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- }
- }
-
- private void add10gen() throws OpenShiftException {
- if (!viewer.getChecked(IEmbeddableCartridge.MONGODB_20)) {
- if (MessageDialog.openQuestion(getShell(), "Embed 10gen Cartridge",
- "To embed 10gen cartridge, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
- } else {
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, false);
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- viewer.setChecked(IEmbeddableCartridge._10GEN_MMS_AGENT_01, false);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
-
- private Shell getShell() {
- return viewer.getControl().getShell();
- }
-
- private IWizardContainer getContainer() {
- return wizardPage.getWizard().getContainer();
- }
-
- private void openLogDialog(final IApplication application) {
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- new CreationLogDialog(getShell(), application).open();
- }
- });
- }
-
- private static class JenkinsApplicationDialog extends InputDialog {
-
- public JenkinsApplicationDialog(Shell shell) {
- super(
- shell,
- "New Jenkins application",
- "To embed Jenkins into your application, you first have to create a separate
Jenkins application. "
- + "Please provide a name for this new Jenkins application (lower-case letters
and digits only):"
- , 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";
- }
-
- if (!StringUtils.isAlphaNumeric(input)) {
- return "The name may only contain lower-case letters and digits.";
- }
- return null;
- }
- }
- }
-}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.net.SocketTimeoutException;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import com.openshift.client.IApplication;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public interface IEmbedCartridgesWizardPageModel {
+
+ public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException, SocketTimeoutException;
+
+ public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException;
+
+ public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException;
+
+ public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException;
+
+ public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException;
+}
\ 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/IEmbedCartridgesWizardPageModel.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/OpenShiftExpressApplicationWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -38,6 +38,7 @@
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.core.EmbedCartridgesOperation;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.ImportFailedException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -56,17 +57,19 @@
public abstract class OpenShiftExpressApplicationWizard extends Wizard implements
IImportWizard, INewWizard {
private final boolean skipCredentialsPage;
-
+
private final OpenShiftExpressApplicationWizardModel wizardModel;
OpenShiftExpressApplicationWizard(final boolean useExistingApplication, final String
wizardTitle) {
this(null, null, null, useExistingApplication, wizardTitle);
}
-
- OpenShiftExpressApplicationWizard(UserDelegate user, IProject project, IApplication
application, boolean useExistingApplication, String wizardTitle) {
+
+ OpenShiftExpressApplicationWizard(UserDelegate user, IProject project, IApplication
application,
+ boolean useExistingApplication, String wizardTitle) {
setWindowTitle(wizardTitle);
setNeedsProgressMonitor(true);
- this.wizardModel = new OpenShiftExpressApplicationWizardModel(user, project,
application, useExistingApplication);
+ this.wizardModel = new OpenShiftExpressApplicationWizardModel(user, project,
application,
+ useExistingApplication);
this.skipCredentialsPage = (user != null);
}
@@ -135,7 +138,7 @@
public boolean performFinish() {
boolean success = getWizardModel().isUseExistingApplication();
if (!success) {
- if(createApplication()) {
+ if (createApplication()) {
success = addRemoveCartridges(
getWizardModel().getApplication(),
getWizardModel().getSelectedEmbeddableCartridges());
}
@@ -146,7 +149,7 @@
wizardModel.addUserToModel();
return success;
}
-
+
private boolean importProject() {
try {
final DelegatingProgressMonitor delegatingMonitor = new DelegatingProgressMonitor();
@@ -174,7 +177,8 @@
return Status.OK_STATUS;
} catch (OpenShiftEndpointException e) {
// TODO: refresh user
- return OpenShiftUIActivator.createErrorStatus("Could not create application
\"{0}\": {1}",
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not create application \"{0}\": {1}",
e, applicationName, e.getRestResponseMessages());
} catch (OpenShiftException e) {
// TODO: refresh user
@@ -193,7 +197,7 @@
private boolean addRemoveCartridges(final IApplication application,
final Set<IEmbeddableCartridge> selectedCartridges) {
try {
- final String applicationName = getWizardModel().getApplication().getName();
+ final String applicationName = application.getName();
IStatus status = WizardUtils.runInWizard(
new Job(NLS.bind("Adding selected embedded cartridges for application
{0}...", applicationName)) {
@@ -201,15 +205,17 @@
protected IStatus run(IProgressMonitor monitor) {
try {
if (selectedCartridges != null && !selectedCartridges.isEmpty()) {
- List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
- embeddableCartridges.addAll(selectedCartridges);
- final List<IEmbeddedCartridge> embeddedCartridges =
application.addEmbeddableCartridges(embeddableCartridges);
+ final List<IEmbeddedCartridge> embeddedCartridges =
+ new EmbedCartridgesOperation(application).execute(
+ new ArrayList<IEmbeddableCartridge>(selectedCartridges)
+ , monitor);
openCreationLogDialog(embeddedCartridges);
}
} catch (OpenShiftEndpointException e) {
// TODO: refresh user
return OpenShiftUIActivator.createErrorStatus(NLS.bind(
- "Could not embed cartridges to application {0}: {1}",
applicationName, e.getRestResponseMessages()));
+ "Could not embed cartridges to application {0}: {1}",
applicationName,
+ e.getRestResponseMessages()));
} catch (OpenShiftException e) {
return OpenShiftUIActivator.createErrorStatus(NLS.bind(
"Could not embed cartridges to application {0}", getWizardModel()
@@ -243,7 +249,8 @@
}
/**
- * A workspace job that will create a new project or enable the selected project to be
used with OpenShift.
+ * A workspace job that will create a new project or enable the selected
+ * project to be used with OpenShift.
*/
class ImportJob extends WorkspaceJob {
@@ -263,11 +270,12 @@
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.\n"
- + "Furthermore publishing to your OpenShift app will eventually override
existing content.\n"
- + "\nDo you wish to continue ?",
+ 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.\n"
+ + "Furthermore publishing to your OpenShift app will eventually override
existing content.\n"
+ + "\nDo you wish to continue ?",
wizardModel.getApplicationName(), wizardModel.getProjectName()),
wizardModel.getApplicationName())) {
return Status.CANCEL_STATUS;
@@ -275,11 +283,12 @@
getWizardModel().configureUnsharedProject(delegatingMonitor);
} else {
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.\n"
- + "Furthermore publishing to your OpenShift app will eventually override
existing content.\n"
- + "\nDo you wish to continue ?",
+ 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.\n"
+ + "Furthermore publishing to your OpenShift app will eventually override
existing content.\n"
+ + "\nDo you wish to continue ?",
wizardModel.getApplicationName(), wizardModel.getProjectName()),
wizardModel.getApplicationName())) {
return Status.CANCEL_STATUS;
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-05-11
14:46:44 UTC (rev 40952)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-05-11
15:08:22 UTC (rev 40953)
@@ -9,27 +9,21 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
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.osgi.util.NLS;
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.express.internal.core.CreateApplicationOperation;
import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.core.console.UserModel;
-import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
-import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
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;
@@ -47,14 +41,14 @@
protected HashMap<String, Object> dataModel = new HashMap<String,
Object>();
- private static final int APP_CREATION_TIMEOUT = 180;
private static final String KEY_SELECTED_EMBEDDABLE_CARTRIDGES =
"selectedEmbeddableCartridges";
public OpenShiftExpressApplicationWizardModel(UserDelegate user) {
this(user, null, null, false);
}
- public OpenShiftExpressApplicationWizardModel(UserDelegate user, IProject project,
IApplication application, boolean useExistingApplication) {
+ public OpenShiftExpressApplicationWizardModel(UserDelegate user, IProject project,
IApplication application,
+ boolean useExistingApplication) {
// default value(s)
setUser(user);
setProject(project);
@@ -92,12 +86,12 @@
addSettingsFiles(importedProjects);
createServerAdapter(monitor, importedProjects);
}
-
+
private void addSettingsFiles(List<IProject> imported) {
Iterator<IProject> i = imported.iterator();
- while(i.hasNext()) {
+ while (i.hasNext()) {
IProject p = i.next();
- if( p.getFolder(".git").exists()) {
+ if (p.getFolder(".git").exists()) {
// This is our project
IApplication app = getApplication();
IProject project = p;
@@ -108,7 +102,7 @@
}
}
}
-
+
/**
* Enables the user chosen, unshared project to be used on the chosen
* OpenShift application. Clones the application git repository, copies the
@@ -189,13 +183,13 @@
private void createServerAdapter(IProgressMonitor monitor, List<IProject>
importedProjects)
throws OpenShiftException {
Assert.isTrue(importedProjects.size() > 0);
- if (isCreateServerAdapter()) {
+ if (isCreateServerAdapter()) {
Assert.isTrue(importedProjects.size() > 0);
IProject project = importedProjects.get(0);
new ServerAdapterFactory().create(project, this, monitor);
}
}
-
+
@Override
public File getRepositoryFile() {
String repositoryPath = getRepositoryPath();
@@ -231,7 +225,7 @@
setApplicationName(application);
setApplicationScaling(application);
setApplicationGearProfile(application);
-
+
}
@Override
@@ -300,7 +294,7 @@
@Override
public IProject getProject() {
String projectName = getProjectName();
- if(projectName == null || projectName.isEmpty()) {
+ if (projectName == null || projectName.isEmpty()) {
return null;
}
return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
@@ -369,68 +363,24 @@
@Override
public ApplicationScale setApplicationScale(final ApplicationScale scale) {
- return (ApplicationScale) setProperty(APPLICATION_SCALE, scale);
+ return (ApplicationScale) setProperty(APPLICATION_SCALE, scale);
}
protected void setApplicationScaling(IApplication application) {
- if(application != null) {
+ if (application != null) {
setApplicationScale(application.getApplicationScale());
}
}
- 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()));
- }
- }
-
- protected IApplication createApplication(final String name, final ICartridge cartridge,
final ApplicationScale scale, final IGearProfile gearProfile, final IProgressMonitor
monitor)
- throws OpenShiftApplicationNotAvailableException, OpenShiftException {
- final UserDelegate user = getUser();
- if (user == null) {
- throw new OpenShiftException("Could not create application, have no valid user
credentials");
- }
- ExecutorService executor = Executors.newFixedThreadPool(1);
- try {
- FutureTask<IApplication> future = new FutureTask<IApplication>(
- new Callable<IApplication>() {
- @Override
- public IApplication call() throws Exception {
- monitor.setTaskName("Creating application \"" + name +
"\"...");
- Logger.debug("creating application...");
- final IApplication application
- = user.createApplication(name, cartridge, scale, gearProfile);
- monitor.beginTask("Waiting for application to be reachable...",
- IProgressMonitor.UNKNOWN);
- Logger.debug("Waiting for application to be reachable...");
- waitForAccessible(application, monitor);
- return application;
- }
- });
- executor.execute(future);
- while (!future.isDone()) {
- if(monitor.isCanceled()) {
- throw new OpenShiftException("Operation was cancelled by user.");
- }
- Thread.sleep(1000);
- }
- final IApplication application = future.get();
- return application;
- } catch (Exception e) { // InterruptedException and ExecutionException
- Throwable cause = e.getCause() !=null ?e.getCause() : e;
- Logger.error("Failed to create application", cause);
- throw new OpenShiftException("Failed to create application: {0}",
cause.getMessage());
- } finally {
- executor.shutdown();
- }
- }
-
public void createApplication(IProgressMonitor monitor) throws
OpenShiftApplicationNotAvailableException,
OpenShiftException {
- IApplication application = createApplication(getApplicationName(),
getApplicationCartridge(), getApplicationScale(), getApplicationGearProfile(), monitor);
+ IApplication application =
+ new CreateApplicationOperation(getUser()).execute(
+ getApplicationName(),
+ getApplicationCartridge(),
+ getApplicationScale(),
+ getApplicationGearProfile(),
+ monitor);
setApplication(application);
}
@@ -469,7 +419,7 @@
public IGearProfile getApplicationGearProfile() {
return (IGearProfile) getProperty(APPLICATION_GEAR_PROFILE);
}
-
+
@Override
public IGearProfile setApplicationGearProfile(IGearProfile gearProfile) {
return (IGearProfile) setProperty(APPLICATION_GEAR_PROFILE, gearProfile);