Author: adietish
Date: 2012-05-11 20:05:49 -0400 (Fri, 11 May 2012)
New Revision: 40967
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
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/ApplicationConfigurationWizardPageModel.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/IEmbedCartridgesWizardPageModel.java
Log:
[JBIDE-10852] switched to use databinding: cartridge selection strategy gets simpler, does
not have to care about UI-state
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
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -16,6 +16,7 @@
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
+import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.observable.list.IObservableList;
@@ -321,7 +322,7 @@
dbc.addValidationStatusProvider(newApplicationTypeValidator);
ControlDecorationSupport.create(newApplicationTypeValidator, SWT.LEFT | SWT.TOP, null,
new CustomControlDecorationUpdater());
-
+
// embeddable cartridges
this.newAppEmbeddableCartridgesGroup = new Group(newAppConfigurationGroup, SWT.NONE);
newAppEmbeddableCartridgesGroup.setText("Embeddable Cartridges");
@@ -333,10 +334,14 @@
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 EmbedCartridgeStrategy(viewer, pageModel, this));
- dbc.bindSet(ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
- BeanProperties.set(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
- .observe(pageModel));
+ viewer.addCheckStateListener(new EmbedCartridgeStrategy(pageModel, this));
+ dbc.bindSet(
+ ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
+ BeanProperties.set(
+ ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
+ .observe(pageModel),
+ new UpdateSetStrategy(UpdateSetStrategy.POLICY_NEVER),
+ null);
this.checkAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
checkAllButton.setText("&Select All");
@@ -452,14 +457,16 @@
@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);
-// } catch (SocketTimeoutException ex) {
-// OpenShiftUIActivator.log("Could not select jenkins cartridge", ex);
-// }
+ // viewer.setAllChecked(true);
+ // try {
+ // addJenkinsCartridge(IEmbeddableCartridge.JENKINS_14);
+ // } catch (OpenShiftException ex) {
+ // OpenShiftUIActivator.log("Could not select jenkins cartridge",
+ // ex);
+ // } catch (SocketTimeoutException ex) {
+ // OpenShiftUIActivator.log("Could not select jenkins cartridge",
+ // ex);
+ // }
}
};
@@ -824,8 +831,9 @@
/**
* Validates that the new application type is selected
+ *
* @author Xavier Coulon
- *
+ *
*/
class NewApplicationTypeValidator extends MultiValidator {
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
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -44,7 +44,6 @@
public static final String PROPERTY_EXISTING_APPLICATION_NAME =
"existingApplicationName";
public static final String PROPERTY_CARTRIDGES = "cartridges";
public static final String PROPERTY_EMBEDDED_CARTRIDGES =
"embeddedCartridges";
- public static final String PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES =
"selectedEmbeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
public static final String PROPERTY_SELECTED_GEAR_PROFILE =
"selectedGearProfile";
public static final String PROPERTY_APPLICATION_NAME = "applicationName";
@@ -376,27 +375,38 @@
return embeddedCartridges;
}
- @Override
- public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException {
- return wizardModel.getSelectedEmbeddableCartridges();
- }
@Override
- public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge)
+ throws OpenShiftException,SocketTimeoutException {
+ Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().add(cartridge);
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
}
@Override
- public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge)
+ throws OpenShiftException,SocketTimeoutException {
+ Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().remove(cartridge);
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
}
+ @Override
+ public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException {
+ return wizardModel.getSelectedEmbeddableCartridges();
+ }
+
public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge>
selectedEmbeddableCartridges) {
firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES,
wizardModel.getSelectedEmbeddableCartridges(),
wizardModel.setSelectedEmbeddableCartridges(selectedEmbeddableCartridges));
}
+ public boolean isSelected(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
+ return getSelectedEmbeddableCartridges().contains(cartridge);
+ }
+
@Override
public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
return getUser().hasApplicationOfType(cartridge);
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java 2012-05-11
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -1,314 +0,0 @@
-/*******************************************************************************
- * 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.)
- * <p>
- * TODO: replaced this manual code by a generic dependency-tree analysis
- * mechanism as soon as OpenShift completed design of cartridge metamodel
- *
- * @author Andre Dietisheim
- */
-public class EmbedCartridgeStrategy implements ICheckStateListener {
-
- private CheckboxTableViewer viewer;
- private IEmbedCartridgesWizardPageModel pageModel;
- private IWizardPage wizardPage;
-
- public EmbedCartridgeStrategy(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) {
- viewer.getControl().getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- viewer.setChecked(cartridge, false);
- }
- });
- return OpenShiftUIActivator.createErrorStatus("Could not create jenkins
application", 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);
- }
- } 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.ROCKMONGO_11, false);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private void removeMongoDb() throws OpenShiftException, SocketTimeoutException {
- boolean removeMongoDb = true;
- 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 {
- removeMongoDb = false;
- }
- }
-
- if (removeMongoDb // mongo to be removed?
- && viewer.getChecked(IEmbeddableCartridge._10GEN_MMS_AGENT_01)) {
- if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
- "If you remove the MongoDB cartridge, you'd also have to remove 10gen MMS
agent.")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
- viewer.setChecked(IEmbeddableCartridge._10GEN_MMS_AGENT_01, false);
- } else {
- removeMongoDb = false;
- }
- }
-
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, !removeMongoDb);
- if (removeMongoDb) { // mongo to be removed?
- 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?")) {
- viewer.setChecked(IEmbeddableCartridge.MONGODB_20, true);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
- } else {
- 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) {
- viewer.getControl().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/EmbedCartridgeStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -0,0 +1,289 @@
+/*******************************************************************************
+ * 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.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.)
+ * <p>
+ * TODO: replaced this manual code by a generic dependency-tree analysis
+ * mechanism as soon as OpenShift completed design of cartridge metamodel
+ *
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgeStrategy implements ICheckStateListener {
+
+ private IEmbedCartridgesWizardPageModel pageModel;
+ private IWizardPage wizardPage;
+
+ public EmbedCartridgeStrategy(IEmbedCartridgesWizardPageModel pageModel, IWizardPage
wizardPage) {
+ this.wizardPage = wizardPage;
+ this.pageModel = pageModel;
+ }
+
+ @Override
+ 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 {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.JENKINS_14);
+ }
+ }
+ }
+
+ 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.selectEmbeddedCartridges(cartridge);
+ openLogDialog(jenkinsApplication);
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ try {
+ pageModel.selectEmbeddedCartridges(cartridge);
+ } catch (Exception ex) {
+ OpenShiftUIActivator.log(ex);
+ }
+ return OpenShiftUIActivator.createErrorStatus("Could not create jenkins
application", e);
+ }
+ }
+
+ }, getContainer());
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ private void addPhpMyAdmin() throws OpenShiftException, SocketTimeoutException {
+ if (!pageModel.isSelected(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);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+ private void addMySql()
+ throws OpenShiftException, SocketTimeoutException {
+ if (pageModel.isSelected(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);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ }
+
+ private void addPostgreSql()
+ throws OpenShiftException, SocketTimeoutException {
+ if (pageModel.isSelected(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.MYSQL_51);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
+ }
+ }
+
+ private void removeMySQL() throws OpenShiftException, SocketTimeoutException {
+ if (pageModel.isSelected(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);
+ }
+ } else {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
+ }
+ }
+
+ private void addRockMongo() throws OpenShiftException, SocketTimeoutException {
+ if (!pageModel.isSelected(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);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+ private void removeMongoDb() throws OpenShiftException, SocketTimeoutException {
+ boolean removeMongoDb = true;
+ if (pageModel.isSelected(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);
+ } else {
+ removeMongoDb = false;
+ }
+ }
+
+ if (removeMongoDb // mongo to be removed?
+ && pageModel.isSelected(IEmbeddableCartridge._10GEN_MMS_AGENT_01)) {
+ if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
+ "If you remove the MongoDB cartridge, you'd also have to remove 10gen MMS
agent.")) {
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
+ } else {
+ removeMongoDb = false;
+ }
+ }
+
+ if (removeMongoDb) { // mongo to be removed?
+ pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
+ }
+ }
+
+ private void add10gen() throws OpenShiftException, SocketTimeoutException {
+ if (!pageModel.isSelected(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);
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
+ }
+ } else {
+ pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
+ }
+ }
+
+ private Shell getShell() {
+ return wizardPage.getControl().getShell();
+ }
+
+ private IWizardContainer getContainer() {
+ return wizardPage.getWizard().getContainer();
+ }
+
+ private void openLogDialog(final IApplication application) {
+ wizardPage.getControl().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/EmbedCartridgeStrategy.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
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -19,10 +19,13 @@
import java.util.concurrent.TimeUnit;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateSetStrategy;
+import org.eclipse.core.databinding.beans.BeanProperties;
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;
@@ -76,7 +79,15 @@
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
- viewer.addCheckStateListener(new EmbedCartridgeStrategy(viewer, pageModel, this));
+// viewer.addCheckStateListener(new EmbedCartridgeStrategy(viewer, pageModel, this));
+ dbc.bindSet(
+ ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
+ BeanProperties.set(
+ EmbedCartridgeWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
+ .observe(pageModel),
+ new UpdateSetStrategy(UpdateSetStrategy.POLICY_NEVER),
+ null);
+ viewer.addCheckStateListener(new EmbedCartridgeStrategy(pageModel, this));
// hiding buttons for now:
https://issues.jboss.org/browse/JBIDE-10399
// Button checkAllButton = new Button(embedGroup, SWT.PUSH);
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
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -12,6 +12,7 @@
import java.net.SocketTimeoutException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -38,7 +39,7 @@
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
private ApplicationWizardModel wizardModel;
-
+
private List<IEmbeddableCartridge> embeddedCartridges = new
ArrayList<IEmbeddableCartridge>();
private Set<IEmbeddableCartridge> selectedCartridges;
@@ -55,11 +56,6 @@
}
selectedCartridges.addAll(application.getEmbeddedCartridges());
}
-
- protected void setSelectedEmbeddedCartridges(List<IEmbeddedCartridge> cartridges)
{
- selectedCartridges.clear();
- selectedCartridges.addAll(cartridges);
- }
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException, SocketTimeoutException {
List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().getEmbeddableCartridges();
@@ -84,6 +80,21 @@
return selectedCartridges;
}
+ public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge> cartridges)
throws SocketTimeoutException, OpenShiftException {
+ setSelectedEmbeddableCartridges(cartridges);
+ }
+
+ protected void setSelectedEmbeddedCartridges(Collection<IEmbeddedCartridge>
cartridges) throws SocketTimeoutException, OpenShiftException {
+ Set<IEmbeddableCartridge> oldValue = getSelectedEmbeddableCartridges();
+ selectedCartridges.clear();
+ selectedCartridges.addAll(cartridges);
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
selectedCartridges);
+ }
+
+ public boolean isSelected(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
+ return getSelectedEmbeddableCartridges().contains(cartridge);
+ }
+
public boolean hasApplication(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
return wizardModel.getUser().hasApplicationOfType(cartridge);
}
@@ -95,13 +106,17 @@
@Override
public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge)
throws OpenShiftException,SocketTimeoutException {
+ Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().add(cartridge);
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
}
@Override
public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge)
throws OpenShiftException,SocketTimeoutException {
+ Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().remove(cartridge);
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
}
public Set<IEmbeddableCartridge> refreshSelectedEmbeddedCartridges()
Modified:
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 2012-05-11
22:24:48 UTC (rev 40966)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java 2012-05-12
00:05:49 UTC (rev 40967)
@@ -25,13 +25,20 @@
*/
public interface IEmbedCartridgesWizardPageModel {
+ public static final String PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES =
"selectedEmbeddableCartridges";
+
public Set<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException, SocketTimeoutException;
public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException;
public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge) throws
OpenShiftException, SocketTimeoutException;
+ public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge>
selectedEmbeddableCartridges) throws SocketTimeoutException, OpenShiftException;
+
+ public boolean isSelected(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