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