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;
+ }
}