Author: adietish
Date: 2011-11-23 13:38:42 -0500 (Wed, 23 Nov 2011)
New Revision: 36572
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreationLogDialog.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/StringUtils.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
Log:
[JBIDE-9927] added a dialog that reports credentials and urls for cartridges that were
embedded / jenkins app that was created
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/StringUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/StringUtils.java 2011-11-23
18:18:45 UTC (rev 36571)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/StringUtils.java 2011-11-23
18:38:42 UTC (rev 36572)
@@ -16,6 +16,8 @@
* @author André Dietisheim
*/
public class StringUtils {
+
+ private static final String LINE_SEPARATOR_KEY = "line.separator";
public static String null2emptyString(String value) {
if (value != null) {
@@ -45,4 +47,9 @@
public String toString(T object);
}
+ public static String getLineSeparator() {
+ return System.getProperty(LINE_SEPARATOR_KEY);
+ }
+
+
}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreationLogDialog.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreationLogDialog.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreationLogDialog.java 2011-11-23
18:38:42 UTC (rev 36572)
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftImages;
+import org.jboss.tools.openshift.express.internal.ui.common.StringUtils;
+
+/**
+ * @author André Dietisheim
+ */
+public class CreationLogDialog extends TitleAreaDialog {
+
+ private LogEntry[] logEntries;
+
+ public CreationLogDialog(Shell parentShell, LogEntry... logEntries) {
+ super(parentShell);
+ this.logEntries = logEntries;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Control control = super.createContents(parent);
+ setupDialog(parent);
+ return control;
+ }
+
+ private void setupDialog(Composite parent) {
+ parent.getShell().setText("Embedded Cartridges");
+ setTitle("Please make note of the credentials and url that were reported when your
cartridges were embedded / application was created. ");
+ setTitleImage(OpenShiftImages.OPENSHIFT_LOGO_WHITE_MEDIUM_IMG);
+ setDialogHelpAvailable(false);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(container);
+ GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(container);
+
+ Label separator = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true,
false).applyTo(separator);
+
+ StyledText logText = new StyledText(container, SWT.BORDER | SWT.V_SCROLL);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true,
false).applyTo(logText);
+ writeLogEntries(logEntries, logText);
+ return container;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+ private void writeLogEntries(LogEntry[] logEntries, StyledText logText) {
+ List<StyleRange> styles = new ArrayList<StyleRange>();
+ StringBuilder builder = new StringBuilder();
+
+ for (LogEntry logEntry : logEntries) {
+ writeLogEntry(logEntry, builder, styles);
+ }
+
+ logText.setText(builder.toString());
+
+ setStyleRanges(logText, styles);
+
+ }
+
+ private void writeLogEntry(LogEntry logEntry, StringBuilder builder,
List<StyleRange> styles) {
+ appendTitle(logEntry.getName(), builder, styles);
+ builder.append(logEntry.getLog());
+ builder.append(StringUtils.getLineSeparator());
+ }
+
+ private void setStyleRanges(StyledText logText, List<StyleRange> styles) {
+ for (StyleRange style : styles) {
+ logText.setStyleRange(style);
+ }
+ }
+
+ private void appendTitle(String title, StringBuilder builder, List<StyleRange>
styles) {
+ StyleRange styleRange = startBoldStyleRange(builder);
+ builder.append(title)
+ .append(StringUtils.getLineSeparator())
+ .append("---------------------------------")
+ .append(StringUtils.getLineSeparator());
+ finishBoldStyleRange(builder, styleRange);
+ styles.add(styleRange);
+ }
+
+ private StyleRange startBoldStyleRange(StringBuilder builder) {
+ StyleRange styleRange = new StyleRange();
+ styleRange.start = builder.length();
+ styleRange.fontStyle = SWT.BOLD;
+ return styleRange;
+ }
+
+ private StyleRange finishBoldStyleRange(StringBuilder builder, StyleRange styleRange) {
+ styleRange.length = builder.length() - styleRange.start;
+ return styleRange;
+ }
+
+ public static class LogEntry {
+
+ private String name;
+ private String log;
+
+ public LogEntry(String name, String log) {
+ this.name = name;
+ this.log = log;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getLog() {
+ return log;
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CreationLogDialog.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 2011-11-23
18:18:45 UTC (rev 36571)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-23
18:38:42 UTC (rev 36572)
@@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -49,11 +50,13 @@
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.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.common.StringUtils;
+import org.jboss.tools.openshift.express.internal.ui.wizard.CreationLogDialog.LogEntry;
/**
* @author André Dietisheim
@@ -164,39 +167,45 @@
} else {
final JenkinsApplicationDialog dialog = new JenkinsApplicationDialog(getShell());
if (dialog.open() == Dialog.OK) {
- try {
- final String name = dialog.getValue();
- WizardUtils.runInWizard(new Job(
- NLS.bind("Creating jenkins application \"{0}\"...", name)) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- model.createJenkinsApplication(name);
- model.getSelectedEmbeddableCartridges().add(cartridge);
- 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
- }
+ 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);
+ 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 {
if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
if (MessageDialog.openQuestion(getShell(), "Embed mysql cartridge",
@@ -217,17 +226,18 @@
}
private void removeMySQLCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException {
+ List<IEmbeddableCartridge> checkedCartridges =
model.getSelectedEmbeddableCartridges();
if (viewer.getChecked(IEmbeddableCartridge.PHPMYADMIN_34)) {
if (MessageDialog.openQuestion(getShell(), "Remove phpmyadmin cartridge",
"If you remove the mysql cartridge, you'd also have to remove
phpmyadmin.")) {
- model.getSelectedEmbeddableCartridges().remove(IEmbeddableCartridge.PHPMYADMIN_34);
- model.getSelectedEmbeddableCartridges().remove(cartridge);
+ checkedCartridges.remove(IEmbeddableCartridge.PHPMYADMIN_34);
+ checkedCartridges.remove(cartridge);
viewer.setChecked(IEmbeddableCartridge.PHPMYADMIN_34, false);
} else {
viewer.setChecked(cartridge, true);
}
} else {
- model.getSelectedEmbeddableCartridges().add(cartridge);
+ checkedCartridges.remove(cartridge);
}
}
@@ -331,6 +341,66 @@
}
}
+ 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())) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ List<IEmbeddableCartridge> addedCartridges = model.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);
+ }
+ return Status.OK_STATUS;
+ }
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private void openLogDialog(final List<IEmbeddableCartridge> cartridges) {
+ if (cartridges.size() == 0) {
+ return;
+ }
+
+ final ArrayList<LogEntry> logEntries = new ArrayList<LogEntry>();
+ for (IEmbeddableCartridge cartridge : cartridges) {
+ logEntries.add(new LogEntry(cartridge.getName(), cartridge.getCreationLog()));
+ }
+
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ new CreationLogDialog(getShell(),
+ logEntries.toArray(new LogEntry[logEntries.size()])).open();
+
+ }
+ });
+ }
+
+ private void openLogDialog(final IApplication application) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ new CreationLogDialog(getShell(),
+ new LogEntry(application.getName(), application.getCreationLog())).open();
+ }
+ });
+ }
+
/**
* Viewer element comparer based on #equals(). The default implementation in
* CheckboxTableViewer compares elements based on instance identity.
@@ -360,32 +430,4 @@
}
}
-
- 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())) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- model.embedCartridges();
- 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);
- }
- return Status.OK_STATUS;
- }
- }, getContainer());
- return queue.poll(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- return false;
- }
- }
-
}
\ No newline at end of file
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 2011-11-23
18:18:45 UTC (rev 36571)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-23
18:38:42 UTC (rev 36572)
@@ -40,7 +40,7 @@
private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
private List<IEmbeddableCartridge> selectedCartridges;
-
+
public EmbedCartridgeWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
}
@@ -48,7 +48,7 @@
public void loadSelectedEmbeddableCartridges() throws OpenShiftException {
selectedCartridges = new ArrayList<IEmbeddableCartridge>();
IApplication application = wizardModel.getApplication();
- if (application == null
+ if (application == null
|| application.getEmbeddedCartridges() == null) {
return;
}
@@ -77,7 +77,7 @@
}
return selectedCartridges;
}
-
+
public boolean hasApplication(ICartridge cartridge) {
try {
return wizardModel.getUser().hasApplication(cartridge);
@@ -89,22 +89,31 @@
}
public IApplication getApplication() {
- return wizardModel.getApplication();
+ return wizardModel.getApplication();
}
- public void createJenkinsApplication(String name) throws OpenShiftException {
- wizardModel.getUser().createApplication(name, ICartridge.JENKINS_14);
+ public IApplication createJenkinsApplication(String name) throws OpenShiftException {
+ IApplication application = wizardModel.getUser().createApplication(name,
ICartridge.JENKINS_14);
+ return application;
}
-
- public void embedCartridges() throws OpenShiftException {
+
+ /**
+ * Embeds/removes the cartridges that were added/removed in this wizard
+ * page.
+ *
+ * @return the cartridges that were added.
+ * @throws OpenShiftException
+ */
+ public List<IEmbeddableCartridge> embedCartridges() throws OpenShiftException {
if (selectedCartridges == null) {
- return;
+ return Collections.emptyList();
}
List<IEmbeddableCartridge> addedCartridges = new
ArrayList<IEmbeddableCartridge>();
List<IEmbeddableCartridge> removedCartridges = new
ArrayList<IEmbeddableCartridge>();
computeAdditionsAndRemovals(addedCartridges, removedCartridges, selectedCartridges);
addEmbeddedCartridges(addedCartridges);
removeEmbeddedCartridges(removedCartridges);
+ return addedCartridges;
}
private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
removedCartridges) throws OpenShiftException {