JBoss Tools SVN: r35251 - in trunk/common/plugins/org.jboss.tools.common.ui: src/org/jboss/tools/common/ui and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-09-30 20:47:00 -0400 (Fri, 30 Sep 2011)
New Revision: 35251
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/BrowserUtil.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ParametrizableWizardPageSupport.java
Removed:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
Log:
[JBIDE-9805] moved MandatoryStringValidator, WizardUtils, etc. to org.jboss.tools.common.ui
Modified: trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-01 00:17:44 UTC (rev 35250)
+++ trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-01 00:47:00 UTC (rev 35251)
@@ -15,9 +15,9 @@
org.eclipse.ui.forms;bundle-version="3.5.100";visibility:=reexport,
org.eclipse.ui.workbench.texteditor;bundle-version="3.7.0",
org.eclipse.jface.text;bundle-version="3.7.0",
- org.eclipse.core.databinding;bundle-version="1.4.0"
+ org.eclipse.core.databinding;bundle-version="1.4.0",
+ org.eclipse.jface.databinding;bundle-version="1.5.0"
Export-Package: org.jboss.tools.common.ui,
- org.jboss.tools.common.ui.browser,
org.jboss.tools.common.ui.databinding,
org.jboss.tools.common.ui.preferences,
org.jboss.tools.common.ui.widget.editor,
Copied: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/BrowserUtil.java (from rev 35198, trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/BrowserUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/BrowserUtil.java 2011-10-01 00:47:00 UTC (rev 35251)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.common.ui;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class BrowserUtil {
+
+ /**
+ * Opens a browser for the given url with the given id. If an error occurs
+ * it will be reported to the given log provider with the given plugin id.
+ *
+ * @param url
+ * the url to open a browser for.
+ * @param browserId
+ * the id for the new browser.
+ * @param pluginId
+ * the plugin id to log for.
+ * @param log
+ * the log provider to log against if an error occurred.
+ */
+ public static void checkedCreateInternalBrowser(String url, String browserId, String pluginId, ILog log) {
+ try {
+ openUrl(url, PlatformUI.getWorkbench().getBrowserSupport().createBrowser(browserId), pluginId, log);
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId, CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ }
+ }
+
+ private static IStatus createErrorStatus(String pluginId, String message, Throwable e,
+ Object... messageArguments) {
+ String formattedMessage = null;
+ if (message != null) {
+ formattedMessage = MessageFormat.format(message, messageArguments);
+ }
+ return new Status(Status.ERROR, pluginId, Status.ERROR, formattedMessage, e);
+ }
+
+ public static void checkedCreateExternalBrowser(String url, String pluginId, ILog log) {
+ try {
+ openUrl(url, PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser(), pluginId, log);
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId, CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ }
+ }
+
+ public static void openUrl(String url, IWebBrowser browser, String pluginId, ILog log) {
+ try {
+ browser.openURL(new URL(url));
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId, CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ } catch (MalformedURLException e) {
+ IStatus errorStatus = createErrorStatus(pluginId, CommonUIMessages.BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL, e,
+ url);
+ log.log(errorStatus);
+ }
+ }
+}
Property changes on: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/BrowserUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java (from rev 35151, trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2011-10-01 00:47:00 UTC (rev 35251)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.common.ui;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author André Dietisheim
+ */
+public class WizardUtils {
+
+ /**
+ * Runs the given job in the given wizard container. In order to have the
+ * wizard displaying a progress bar, you need to set
+ * Wizard#setNeedsProgressMonitor to <code>true</code>.
+ *
+ *
+ * @param job
+ * the job to run
+ * @param container
+ * the wizard container to run the job in
+ * @throws InvocationTargetException
+ * the invocation target exception
+ * @throws InterruptedException
+ * the interrupted exception
+ *
+ * @author André Dietisheim
+ *
+ * @see IWizardContainer#run(boolean, boolean, IRunnableWithProgress)
+ * @see Job
+ */
+ public static void runInWizard(final Job job, IWizardContainer container) throws InvocationTargetException,
+ InterruptedException {
+ container.run(true, false, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ monitor.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
+ final CountDownLatch latch = new CountDownLatch(1);
+ job.addJobChangeListener(new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ latch.countDown();
+ }
+ });
+ job.schedule();
+ latch.await();
+ monitor.done();
+ }
+ });
+ }
+
+ /**
+ * Runs the given job in the given wizard container.
+ * <p>
+ * Furhtermore it updates the models and targets of the given data binding
+ * context. This might be necessary if the given job will change widget
+ * enablements in the calling wizard page. The reason for is that the runner
+ * saves the widget enablement states when it's up to execute the runnable.
+ * It then restores those states once he finished executing the runnable. It
+ * may therefore restore incorrect states since the job changed the
+ * enablements when it was run.
+ *
+ * @param job
+ * the job
+ * @param container
+ * the container
+ * @param dbc
+ * the dbc
+ * @throws InvocationTargetException
+ * the invocation target exception
+ * @throws InterruptedException
+ * the interrupted exception
+ */
+ public static void runInWizard(final Job job, IWizardContainer container, final DataBindingContext dbc)
+ throws InvocationTargetException, InterruptedException {
+ runInWizard(job, container);
+ dbc.updateTargets();
+ dbc.updateModels();
+ }
+
+ /**
+ * Flips to the next wizard page or finishes the current wizard.
+ *
+ * @param wizardPage
+ * the wizard page this call is executed in
+ */
+ public static void nextPageOrFinish(IWizardPage wizardPage) {
+ IWizard wizard = wizardPage.getWizard();
+ if (wizardPage.canFlipToNextPage()) {
+ IWizardPage nextPage = wizard.getNextPage(wizardPage);
+ wizard.getContainer().showPage(nextPage);
+ } else if (wizard.canFinish()) {
+ if (wizard.performFinish()) {
+ wizard.getContainer().getShell().close();
+ }
+ }
+ }
+
+ public static void openWizardDialog(IWizard wizard, Shell shell) {
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ dialog.create();
+ dialog.open();
+ }
+}
Property changes on: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ParametrizableWizardPageSupport.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ParametrizableWizardPageSupport.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ParametrizableWizardPageSupport.java 2011-10-01 00:47:00 UTC (rev 35251)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.common.ui.databinding;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.dialog.DialogPageSupport;
+import org.eclipse.jface.wizard.WizardPage;
+
+/**
+ * @author André Dietisheim
+ */
+public class ParametrizableWizardPageSupport extends DialogPageSupport {
+
+ private int nonValidatingSeverity;
+
+ private ParametrizableWizardPageSupport(int nonValidatingSeverity, WizardPage wizardPage, DataBindingContext dbc) {
+ super(wizardPage, dbc);
+ this.nonValidatingSeverity = nonValidatingSeverity;
+ }
+
+ /**
+ * Creates a wizard page support that will not validate if the validation
+ * status is IStatus#ERROR or IStatus#CANCEL.
+ *
+ * @param wizardPage
+ * the wizardpage to apply this support to
+ * @param dbc
+ * the databinding context to use
+ * @return the wizard page support that was created
+ */
+ public static ParametrizableWizardPageSupport create(WizardPage wizardPage, DataBindingContext dbc) {
+ return create(IStatus.ERROR | IStatus.CANCEL, wizardPage, dbc);
+ }
+
+ /**
+ * Creates a wizard page support that will not validate for the given status
+ * mask (severity).
+ *
+ * @param nonValidatingSeverity the status severity mask that will not validate
+ * @param wizardPage
+ * the wizardpage to apply this support to
+ * @param dbc
+ * the databinding context to use
+ * @return the wizard page support that was created
+ */
+ public static ParametrizableWizardPageSupport create(int nonValidatingSeverity, WizardPage wizardPage,
+ DataBindingContext dbc) {
+ return new ParametrizableWizardPageSupport(nonValidatingSeverity, wizardPage, dbc);
+ }
+
+ protected void handleStatusChanged() {
+ super.handleStatusChanged();
+ boolean pageComplete = true;
+ if (currentStatusStale) {
+ pageComplete = false;
+ } else if (currentStatus != null) {
+ pageComplete = !currentStatus.matches(nonValidatingSeverity);
+ }
+ ((WizardPage) getDialogPage()).setPageComplete(pageComplete);
+ }
+}
Property changes on: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ParametrizableWizardPageSupport.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
13 years, 2 months
JBoss Tools SVN: r35250 - trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-09-30 20:17:44 -0400 (Fri, 30 Sep 2011)
New Revision: 35250
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/AbstractOpenshiftWizardPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ApplicationWizardPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ServerAdapterWizardModel.java
Log:
[JBIDE-9793] implementing ApplicationSelectionWizardPage
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/AbstractOpenshiftWizardPage.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/AbstractOpenshiftWizardPage.java 2011-09-30 23:57:59 UTC (rev 35249)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/AbstractOpenshiftWizardPage.java 2011-10-01 00:17:44 UTC (rev 35250)
@@ -16,6 +16,8 @@
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
import org.jboss.ide.eclipse.as.openshift.ui.internal.OpenshiftImages;
import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
@@ -37,14 +39,23 @@
@Override
public void createControl(Composite parent) {
- DataBindingContext dbc = new DataBindingContext();
+ final DataBindingContext dbc = new DataBindingContext();
ParametrizableWizardPageSupport.create(
IStatus.ERROR | IStatus.INFO | IStatus.WARNING | IStatus.CANCEL, this,
dbc);
Composite container = new Composite(parent, SWT.NONE);
setControl(container);
+ container.addListener(SWT.Show, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ onPageVisible(dbc);
+ }
+ });
doCreateControls(container, dbc);
}
+ protected void onPageVisible(DataBindingContext dbc) {
+ }
+
protected abstract void doCreateControls(Composite parent, DataBindingContext dbc);
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ApplicationWizardPage.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ApplicationWizardPage.java 2011-09-30 23:57:59 UTC (rev 35249)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ApplicationWizardPage.java 2011-10-01 00:17:44 UTC (rev 35250)
@@ -10,23 +10,103 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.ui.internal.wizard;
+import java.util.Collection;
+
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.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.ViewerSupport;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.as.openshift.core.IApplication;
+import org.jboss.ide.eclipse.as.openshift.core.IUser;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.ui.internal.OpenshiftUIActivator;
+import org.jboss.tools.common.ui.WizardUtils;
/**
* @author André Dietisheim
*/
public class ApplicationWizardPage extends AbstractOpenshiftWizardPage {
+ private TableViewer viewer;
+
protected ApplicationWizardPage(IWizard wizard, ServerAdapterWizardModel model) {
- super("Application selection", "Please select an Openshift Express application to use", "Application selection", wizard, model);
+ super("Application selection", "Please select an Openshift Express application to use",
+ "Application selection", wizard, model);
}
-
+
@Override
protected void doCreateControls(Composite container, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().numColumns(1).margins(10, 10).applyTo(container);
+
+ Group group = new Group(container, SWT.BORDER);
+ group.setText("Available applications");
+ GridDataFactory.fillDefaults().hint(600, 300).applyTo(group);
+ FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
+ fillLayout.marginHeight = 10;
+ fillLayout.marginWidth = 10;
+ group.setLayout(fillLayout);
+ Table table = new Table(group, SWT.BORDER | SWT.V_SCROLL);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ this.viewer = new TableViewer(table);
}
+
+ @Override
+ protected void onPageVisible(DataBindingContext dbc) {
+ try {
+ WizardUtils.runInWizard(new LoadApplicationsJob(), getWizard().getContainer(), dbc);
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+
+ protected void bindApplications(final Collection<IApplication> applications, final TableViewer viewer) {
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ display.syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ IObservableList input = new WritableList(applications, IApplication.class);
+ ViewerSupport.bind(viewer, input, BeanProperties.values(new String[] { "name", "applicationUrl" }));
+ }
+ });
+ }
+
+ private class LoadApplicationsJob extends Job {
+ private LoadApplicationsJob() {
+ super("Loading applications");
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ IUser user = model.getUser();
+ if (user == null) {
+ return Status.OK_STATUS;
+ }
+ bindApplications(user.getApplications(), viewer);
+ return Status.OK_STATUS;
+ } catch (OpenshiftException e) {
+ return new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
+ "Could not load applications from Openshift Express");
+ }
+ }
+ }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ServerAdapterWizardModel.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ServerAdapterWizardModel.java 2011-09-30 23:57:59 UTC (rev 35249)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.ui/src/org/jboss/ide/eclipse/as/openshift/ui/internal/wizard/ServerAdapterWizardModel.java 2011-10-01 00:17:44 UTC (rev 35250)
@@ -33,6 +33,7 @@
private String rhLogin;
private String password;
private IStatus credentialsValidity;
+ private IUser user;
public ServerAdapterWizardModel() {
this.serverUrl = IOpenshiftService.BASE_URL;
@@ -74,13 +75,17 @@
public void validateCredentials() {
IStatus status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID, "Your credentails are not valid.");
try {
- IUser user = new User(getRhLogin(), getPassword());
+ this.user = new User(getRhLogin(), getPassword());
if(user.isValid()) {
status = Status.OK_STATUS;
}
} catch (OpenshiftException e) {
- // do nothing
+ this.user = null;
}
setCredentialsStatus(status);
}
+
+ public IUser getUser() {
+ return user;
+ }
}
13 years, 2 months