Author: rob.stryker(a)jboss.com
Date: 2010-08-04 04:02:56 -0400 (Wed, 04 Aug 2010)
New Revision: 23908
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/rse/ui/RSEDeploymentPreferenceUI.java
Log:
JBIDE-6775 - fixing editor startup
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/rse/ui/RSEDeploymentPreferenceUI.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/rse/ui/RSEDeploymentPreferenceUI.java 2010-08-04
07:48:17 UTC (rev 23907)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/rse/ui/RSEDeploymentPreferenceUI.java 2010-08-04
08:02:56 UTC (rev 23908)
@@ -12,10 +12,11 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.rse.core.RSECorePlugin;
+import org.eclipse.rse.core.events.ISystemModelChangeEvent;
+import org.eclipse.rse.core.events.ISystemModelChangeListener;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.files.ui.dialogs.SystemRemoteFileDialog;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
-import org.eclipse.rse.ui.widgets.SystemHostCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -23,14 +24,16 @@
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.rse.core.RSERemotePublishHandler;
import org.jboss.ide.eclipse.as.rse.core.RSEUtils;
import org.jboss.ide.eclipse.as.ui.UIUtil;
import org.jboss.ide.eclipse.as.ui.editor.IDeploymentTypeUI;
@@ -51,9 +54,10 @@
public static class RSEDeploymentPreferenceComposite extends Composite {
private ServerModeSection modeSection;
- private SystemHostCombo combo;
+ private CustomSystemHostCombo combo;
private Text rseServerHome,rseServerConfig;
private Button rseBrowse;
+ private ModifyListener comboMListener;
public RSEDeploymentPreferenceComposite(Composite parent, int style, ServerModeSection
modeSection) {
super(parent, style);
this.modeSection = modeSection;
@@ -62,14 +66,15 @@
child.setLayoutData(UIUtil.createFormData2(0, 0, null, 0, 0, 5, 100, 0));
child.setLayout(new GridLayout());
String current = modeSection.getServer().getAttribute(RSEUtils.RSE_SERVER_HOST,
RSEUtils.RSE_SERVER_DEFAULT_HOST);
- combo = new SystemHostCombo(child, SWT.NULL, findHost(current), false,
+ combo = new CustomSystemHostCombo(child, SWT.NULL, current, "files");
//$NON-NLS-1$
/* ISubSystemConfigurationCategories.SUBSYSTEM_CATEGORY_FILES*/
- "files");
- combo.addModifyListener(new ModifyListener() {
+ // "files");
+ comboMListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
rseHostChanged();
}
- });
+ };
+ combo.getCombo().addModifyListener(comboMListener);
Label serverHomeLabel = new Label(this, SWT.NONE);
serverHomeLabel.setText("Remote Server Home: ");
rseBrowse = new Button(this, SWT.DEFAULT);
@@ -106,6 +111,7 @@
}});
}
+
protected void browseClicked() {
SystemRemoteFileDialog d = new SystemRemoteFileDialog(
rseBrowse.getShell(), "Browse remote system", combo.getHost());
@@ -124,9 +130,13 @@
}
protected void rseHostChanged() {
- modeSection.getCommandManager().execute(new ChangeServerPropertyCommand(
- modeSection.getServer(), RSEUtils.RSE_SERVER_HOST, combo.getHost().getAliasName(),
- "Change RSE Host"));
+ String hostName = combo.getHost() == null ? null : combo.getHost().getAliasName();
+ String oldVal = modeSection.getServer().getAttribute(RSEUtils.RSE_SERVER_HOST,
(String)null);
+ if( !hostName.equals(oldVal)) {
+ modeSection.getCommandManager().execute(new ChangeServerPropertyCommand(
+ modeSection.getServer(), RSEUtils.RSE_SERVER_HOST, hostName,
+ "Change RSE Host"));
+ }
}
protected void serverHomeChanged() {
@@ -141,15 +151,113 @@
"Change RSE Server's Configuration"));
}
- public IHost findHost(String name) {
- IHost[] hosts = RSECorePlugin.getTheSystemRegistry().getHosts();
- for( int i = 0; i < hosts.length; i++ ) {
- if( hosts[i].getAliasName().equals(name))
- return hosts[i];
+ public class CustomSystemHostCombo extends Composite implements ModifyListener,
ISystemModelChangeListener {
+ private String fileSubSystem;
+ private Combo combo;
+ private IHost currentHost;
+ private String currentHostName;
+ private IHost[] hosts;
+ private String[] hostsAsStrings;
+ public CustomSystemHostCombo(Composite parent, int style, String initialHostName,
String fileSubSystem) {
+ super(parent, style);
+ this.fileSubSystem = fileSubSystem;
+ this.currentHostName = initialHostName;
+ this.hosts =
RSECorePlugin.getTheSystemRegistry().getHostsBySubSystemConfigurationCategory(fileSubSystem);
+ this.currentHost = findHost(initialHostName);
+ RSECorePlugin.getTheSystemRegistry().addSystemModelChangeListener(this);
+
+ // Where I belong in the parent
+ GridData data = new GridData();
+ // horizontal clues
+ data.horizontalAlignment = GridData.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.widthHint = 200;
+ // vertical clues
+ data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; //GridData.CENTER;
+ data.grabExcessVerticalSpace = false; // true;
+ this.setLayoutData(data);
+
+ // What's inside me
+ setLayout(new FormLayout());
+ Label l = new Label(this, SWT.NONE);
+ l.setText("Host");
+ combo = new Combo(this, SWT.DEFAULT | SWT.READ_ONLY);
+ l.setLayoutData(UIUtil.createFormData2(0, 5, null, 0, 0, 0, null, 0));
+ combo.setLayoutData(UIUtil.createFormData2(0, 0, null, 0, l, 5, 100, -5));
+ refreshConnections();
+ combo.addModifyListener(this);
}
- return null;
+
+ public IHost findHost(String name) {
+ for( int i = 0; i < hosts.length; i++ ) {
+ if( hosts[i].getAliasName().equals(name))
+ return hosts[i];
+ }
+ return null;
+ }
+
+ public Combo getCombo() {
+ return combo;
+ }
+
+ public IHost getHost() {
+ return currentHost;
+ }
+
+ public String getHostName() {
+ return currentHostName;
+ }
+
+ public void refreshConnections() {
+ hosts =
RSECorePlugin.getTheSystemRegistry().getHostsBySubSystemConfigurationCategory(fileSubSystem);
+ hostsAsStrings = new String[hosts.length];
+ int currentHostIndex = -1;
+ for( int i = 0; i < hosts.length; i++ ) {
+ hostsAsStrings[i] = hosts[i].getAliasName();
+ if( currentHostIndex == -1 && currentHostName != null
+ && hostsAsStrings[i].equals(currentHostName)) {
+ currentHostIndex = i;
+ }
+ }
+
+ // refill the combo thingie
+ combo.setItems(hostsAsStrings);
+ if( currentHostIndex != -1 ) // set the current host
+ combo.select(currentHostIndex);
+ else
+ combo.clearSelection();
+ }
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ int index = combo.getSelectionIndex();
+ if( index != -1 ) {
+ String s = combo.getItem(index);
+ for( int i = 0; i < hosts.length; i++ ) {
+ if( hosts[i].getAliasName().equals(s)) {
+ currentHost = hosts[i];
+ currentHostName = currentHost.getAliasName();
+ return;
+ }
+ }
+ }
+ }
+ public void systemModelResourceChanged(ISystemModelChangeEvent event) {
+ if( combo.isDisposed())
+ return;
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run() {
+ combo.removeModifyListener(comboMListener);
+ refreshConnections();
+ combo.addModifyListener(comboMListener);
+ }
+ });
+ }
+ @Override
+ public void dispose () {
+ super.dispose();
+ RSECorePlugin.getTheSystemRegistry().removeSystemModelChangeListener(this);
+ }
}
}
-
-
}