Author: rob.stryker(a)jboss.com
Date: 2008-05-19 19:45:48 -0400 (Mon, 19 May 2008)
New Revision: 8202
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/views/server/preferencepages/JBossServersPreferencePage.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploySection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
Log:
JBIDE-2235 - also trying to fix undo-ability for most options.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploySection.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploySection.java 2008-05-19
20:06:09 UTC (rev 8201)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploySection.java 2008-05-19
23:45:48 UTC (rev 8202)
@@ -47,7 +47,6 @@
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.internal.ServerPlugin;
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
import org.eclipse.wst.server.ui.editor.ServerEditorSection;
@@ -55,6 +54,7 @@
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.ui.Messages;
/**
@@ -64,19 +64,18 @@
*/
public class DeploySection extends ServerEditorSection {
- private Text text;
- private Text tempDeployText;
-
+ private Text deployText, tempDeployText;
+ private ModifyListener deployListener, tempDeployListener;
+ private ServerAttributeHelper helper;
public DeploySection() {
- // TODO Auto-generated constructor stub
}
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
+ helper = new ServerAttributeHelper(server.getOriginal(), server);
}
- public void createSection(Composite parent)
- {
+ public void createSection(Composite parent) {
super.createSection(parent);
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
@@ -92,13 +91,14 @@
Label descriptionLabel = toolkit.createLabel(composite,
Messages.swf_DeploymentDescription);
Label label = toolkit.createLabel(composite, Messages.swf_DeployDirectory);
- text = toolkit.createText(composite, getDeployDir(), SWT.BORDER);
- text.addModifyListener(new ModifyListener() {
+ deployText = toolkit.createText(composite, getDeployDir(), SWT.BORDER);
+ deployListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
- execute(new SetDeployDirCommand(server, text, text.getText()));
+ execute(new SetDeployDirCommand());
getSaveStatus();
}
- });
+ };
+ deployText.addModifyListener(deployListener);
Button button = toolkit.createButton(composite, Messages.browse, SWT.PUSH);
button.addSelectionListener(new SelectionListener() {
@@ -106,21 +106,22 @@
}
public void widgetSelected(SelectionEvent e) {
DirectoryDialog d = new DirectoryDialog(new Shell());
- d.setFilterPath(text.getText());
+ d.setFilterPath(deployText.getText());
String x = d.open();
if( x != null )
- text.setText(x);
+ deployText.setText(x);
}
});
Label tempDeployLabel = toolkit.createLabel(composite,
Messages.swf_TempDeployDirectory);
tempDeployText = toolkit.createText(composite, getTempDeployDir(), SWT.BORDER);
- tempDeployText.addModifyListener(new ModifyListener() {
+ tempDeployListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
- execute(new SetTempDeployDirCommand(server, tempDeployText,
tempDeployText.getText()));
+ execute(new SetTempDeployDirCommand());
getSaveStatus();
}
- });
+ };
+ tempDeployText.addModifyListener(tempDeployListener);
Button tempDeployButton = toolkit.createButton(composite, Messages.browse, SWT.PUSH);
tempDeployButton.addSelectionListener(new SelectionListener() {
@@ -144,7 +145,7 @@
// first row
FormData labelData = new FormData();
labelData.left = new FormAttachment(0,5);
- labelData.right = new FormAttachment(text,-5);
+ labelData.right = new FormAttachment(deployText,-5);
labelData.top = new FormAttachment(descriptionLabel,5);
label.setLayoutData(labelData);
@@ -152,7 +153,7 @@
textData.left = new FormAttachment(button, -305);
textData.top = new FormAttachment(descriptionLabel,5);
textData.right = new FormAttachment(button, -5);
- text.setLayoutData(textData);
+ deployText.setLayoutData(textData);
FormData buttonData = new FormData();
buttonData.right = new FormAttachment(100,-5);
@@ -163,20 +164,20 @@
// second row
FormData tempLabelData = new FormData();
tempLabelData.left = new FormAttachment(0,5);
- tempLabelData.right = new FormAttachment(text, -5);
- tempLabelData.top = new FormAttachment(text,5);
+ tempLabelData.right = new FormAttachment(deployText, -5);
+ tempLabelData.top = new FormAttachment(deployText,5);
tempDeployLabel.setLayoutData(tempLabelData);
FormData tempTextData = new FormData();
tempTextData.left = new FormAttachment(tempDeployButton, -305);
- tempTextData.top = new FormAttachment(text,5);
+ tempTextData.top = new FormAttachment(deployText,5);
tempTextData.right = new FormAttachment(tempDeployButton, -5);
tempDeployText.setLayoutData(tempTextData);
FormData tempButtonData = new FormData();
tempButtonData.right = new FormAttachment(100,-5);
tempButtonData.left = new FormAttachment(100,-100);
- tempButtonData.top = new FormAttachment(text,5);
+ tempButtonData.top = new FormAttachment(deployText,5);
tempDeployButton.setLayoutData(tempButtonData);
toolkit.paintBordersFor(composite);
@@ -200,8 +201,8 @@
public IStatus[] getSaveStatus() {
String error = "";
List status = new ArrayList();
- if(!new Path(text.getText()).toFile().exists()) {
- String msg = "The deploy directory \"" + text.getText() + "\"
does not exist.";
+ if(!new Path(deployText.getText()).toFile().exists()) {
+ String msg = "The deploy directory \"" + deployText.getText() +
"\" does not exist.";
status.add(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, msg));
error = msg + "\n";
}
@@ -218,49 +219,47 @@
- public static class SetDeployDirCommand extends ServerCommand {
+ public class SetDeployDirCommand extends ServerCommand {
private String oldDir;
private String newDir;
private Text text;
- public SetDeployDirCommand(IServerWorkingCopy wc, Text text, String newDir) {
- super(wc, "SetDeployDirCommand");
- this.text = text;
- this.newDir = newDir;
- if( wc instanceof ServerWorkingCopy ) {
- this.oldDir = ((ServerWorkingCopy)wc).getAttribute(DeployableServer.DEPLOY_DIRECTORY,
"");
- }
+ private ModifyListener listener;
+ public SetDeployDirCommand() {
+ super(DeploySection.this.server, "Set Deploy Directory");
+ this.text = deployText;
+ this.newDir = deployText.getText();
+ this.listener = deployListener;
+ this.oldDir = helper.getAttribute(DeployableServer.DEPLOY_DIRECTORY, "");
}
public void execute() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(DeployableServer.DEPLOY_DIRECTORY, newDir);
+ helper.setAttribute(DeployableServer.DEPLOY_DIRECTORY, newDir);
}
public void undo() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(DeployableServer.DEPLOY_DIRECTORY, oldDir);
+ helper.setAttribute(DeployableServer.DEPLOY_DIRECTORY, oldDir);
text.setText(oldDir);
}
}
- public static class SetTempDeployDirCommand extends ServerCommand {
+ public class SetTempDeployDirCommand extends ServerCommand {
private String oldDir;
private String newDir;
private Text text;
- public SetTempDeployDirCommand(IServerWorkingCopy wc, Text text, String newDir) {
- super(wc, "SetDeployDirCommand");
- this.text = text;
- this.newDir = newDir;
- if( wc instanceof ServerWorkingCopy ) {
- this.oldDir =
((ServerWorkingCopy)wc).getAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY,
"");
- }
+ private ModifyListener listener;
+ public SetTempDeployDirCommand() {
+ super(DeploySection.this.server, "Set Temporary Deploy Directory");
+ text = tempDeployText;
+ newDir = tempDeployText.getText();
+ listener = tempDeployListener;
+ oldDir = helper.getAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, "");
}
public void execute() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY,
newDir);
+ helper.setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, newDir);
}
public void undo() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY,
oldDir);
+ text.removeModifyListener(listener);
+ helper.setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, oldDir);
text.setText(oldDir);
+ text.addModifyListener(listener);
}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java 2008-05-19
23:45:48 UTC (rev 8202)
@@ -0,0 +1,177 @@
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.ui.editor.ServerEditorSection;
+import org.eclipse.wst.server.ui.internal.command.ServerCommand;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.server.IServerPollingAttributes;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
+
+/**
+ *
+ * @author rob Stryker (rob.stryker(a)redhat.com)
+ *
+ */
+public class PollerSection extends ServerEditorSection {
+ private Combo startPollerCombo, stopPollerCombo;
+ private Composite pollers;
+ private String[] startupTypesStrings, shutdownTypesStrings;
+ private ServerStatePollerType[] startupTypes, shutdownTypes;
+ private ModifyListener startPollerListener;
+ private ModifyListener stopPollerListener;
+ protected ServerAttributeHelper helper;
+
+ public void init(IEditorSite site, IEditorInput input) {
+ super.init(site, input);
+ helper = new ServerAttributeHelper(server.getOriginal(), server);
+ }
+
+ public void createSection(Composite parent) {
+ super.createSection(parent);
+ findPossiblePollers();
+ createUI(parent);
+ addListeners();
+ }
+
+ protected void createUI(Composite parent) {
+
+ FormToolkit toolkit = new FormToolkit(parent.getDisplay());
+ Section section = toolkit.createSection(parent,
ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED|ExpandableComposite.TITLE_BAR);
+ section.setText("Server Polling");
+ section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL |
GridData.VERTICAL_ALIGN_FILL));
+
+ Composite composite = toolkit.createComposite(section);
+ composite.setLayout(new FormLayout());
+
+ pollers = toolkit.createComposite(composite);
+ pollers.setLayout(new GridLayout(2, false));
+
+ // create widgets
+ Label start, stop;
+ start = new Label(pollers, SWT.NONE);
+ startPollerCombo = new Combo(pollers, SWT.READ_ONLY);
+ stop = new Label(pollers, SWT.NONE);
+ stopPollerCombo = new Combo(pollers, SWT.READ_ONLY);
+
+ start.setText("Startup Poller");
+ stop.setText("Shutdown Poller");
+
+ // set items
+ startPollerCombo.setItems(startupTypesStrings);
+ stopPollerCombo.setItems(shutdownTypesStrings);
+
+ startPollerCombo.setEnabled(true);
+ stopPollerCombo.setEnabled(true);
+ String currentStartId =
helper.getAttribute(IServerPollingAttributes.STARTUP_POLLER_KEY,
IServerPollingAttributes.DEFAULT_STARTUP_POLLER);
+ String currentStopId =
helper.getAttribute(IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
IServerPollingAttributes.DEFAULT_SHUTDOWN_POLLER);
+ startPollerCombo.select(startPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStartId).getName()));
+ stopPollerCombo.select(stopPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStopId).getName()));
+
+ toolkit.paintBordersFor(composite);
+ section.setClient(composite);
+ }
+
+ protected void findPossiblePollers() {
+ startupTypes = ExtensionManager.getDefault().getStartupPollers();
+ shutdownTypes = ExtensionManager.getDefault().getShutdownPollers();
+ startupTypesStrings = new String[startupTypes.length];
+ shutdownTypesStrings = new String[shutdownTypes.length];
+
+ for( int i = 0; i < startupTypes.length; i++ ) {
+ startupTypesStrings[i] = startupTypes[i].getName();
+ }
+ for( int i = 0; i < shutdownTypes.length; i++ ) {
+ shutdownTypesStrings[i] = shutdownTypes[i].getName();
+ }
+ }
+
+ protected void addListeners() {
+ startPollerListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ execute(new SetStartupPollerCommand(server));
+ }
+ };
+ stopPollerListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ execute(new SetStopPollerCommand(server));
+ }
+ };
+
+ startPollerCombo.addModifyListener(startPollerListener);
+ stopPollerCombo.addModifyListener(stopPollerListener);
+ }
+
+ public class SetStartupPollerCommand extends SetPollerCommand {
+ public SetStartupPollerCommand(IServerWorkingCopy server) {
+ super(server, "Change Start Poller",
IServerPollingAttributes.STARTUP_POLLER_KEY,
+ IServerPollingAttributes.DEFAULT_STARTUP_POLLER,
+ startupTypes, startPollerCombo, startPollerListener);
+ }
+ }
+
+ public class SetStopPollerCommand extends SetPollerCommand {
+ public SetStopPollerCommand(IServerWorkingCopy server) {
+ super(server, "Change Stop Poller",
IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
+ IServerPollingAttributes.DEFAULT_SHUTDOWN_POLLER,
+ shutdownTypes, stopPollerCombo, stopPollerListener);
+ }
+ }
+
+
+ public class SetPollerCommand extends ServerCommand {
+ private String preChange;
+ private String attributeKey;
+ private String defaultValue;
+ private ServerStatePollerType[] pollerArray;
+ private Combo combo;
+ private ModifyListener listener;
+ public SetPollerCommand(IServerWorkingCopy server, String name,
+ String attributeKey, String defaultValue, ServerStatePollerType[] pollerArray,
+ Combo pollerCombo, ModifyListener listener) {
+ super(server, name);
+ this.attributeKey = attributeKey;
+ this.defaultValue = defaultValue;
+ this.pollerArray = pollerArray;
+ this.combo = pollerCombo;
+ this.listener = listener;
+ }
+ public void execute() {
+ preChange = helper.getAttribute(attributeKey, defaultValue);
+ helper.setAttribute(attributeKey, pollerArray[combo.getSelectionIndex()].getId());
+ }
+
+ public void undo() {
+ helper.setAttribute(attributeKey, preChange);
+ combo.removeModifyListener(listener);
+ int ind = findIndex(preChange);
+ if( ind == -1 )
+ combo.clearSelection();
+ else
+ combo.select(ind);
+ combo.addModifyListener(listener);
+ }
+
+ protected int findIndex(String id) {
+ for( int i = 0; i < pollerArray.length; i++)
+ if( pollerArray[i].getId().equals(id))
+ return i;
+ return -1;
+ }
+ }
+
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java 2008-05-19
20:06:09 UTC (rev 8201)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java 2008-05-19
23:45:48 UTC (rev 8202)
@@ -34,10 +34,10 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.wst.server.core.IServerWorkingCopy;
-import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
import org.eclipse.wst.server.ui.editor.ServerEditorSection;
import org.eclipse.wst.server.ui.internal.command.ServerCommand;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.ui.Messages;
/**
@@ -47,8 +47,12 @@
*/
public class ServerPasswordSection extends ServerEditorSection {
+ private ModifyListener nameModifyListener, passModifyListener;
+ private Text nameText, passText;
+ private ServerAttributeHelper helper;
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
+ helper = new ServerAttributeHelper(server.getOriginal(), server);
}
public void createSection(Composite parent) {
@@ -66,60 +70,78 @@
GridData d = new GridData(); d.horizontalSpan = 2;
explanation.setLayoutData(d);
- Label name = toolkit.createLabel(composite, Messages.swf_Username);
- final Text nameText = toolkit.createText(composite,
((ServerWorkingCopy)server).getAttribute(JBossServer.SERVER_USERNAME, ""));
- Label pass = toolkit.createLabel(composite, Messages.swf_Password);
- final Text passText = toolkit.createText(composite,
((ServerWorkingCopy)server).getAttribute(JBossServer.SERVER_PASSWORD, ""));
+ toolkit.createLabel(composite, Messages.swf_Username);
+ String n = helper.getAttribute(JBossServer.SERVER_USERNAME, "");
+ String p = helper.getAttribute(JBossServer.SERVER_PASSWORD, "");
+ nameText = toolkit.createText(composite, n);
+ toolkit.createLabel(composite, Messages.swf_Password);
+ passText = toolkit.createText(composite, p);
d = new GridData(); d.grabExcessHorizontalSpace = true; d.widthHint = 100;
nameText.setLayoutData(d);
d = new GridData(); d.grabExcessHorizontalSpace = true; d.widthHint = 100;
passText.setLayoutData(d);
-
- nameText.addModifyListener(new ModifyListener() {
+ nameModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
- execute(new SetVarCommand(server, nameText, nameText.getText(),
JBossServer.SERVER_USERNAME));
+ execute(new SetUserCommand(server));
}
- });
+ };
- passText.addModifyListener(new ModifyListener() {
+ passModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
- execute(new SetVarCommand(server, passText, passText.getText(),
JBossServer.SERVER_PASSWORD));
+ execute(new SetPassCommand(server));
}
- });
+ };
+ nameText.addModifyListener(nameModifyListener);
+ passText.addModifyListener(passModifyListener);
toolkit.paintBordersFor(composite);
section.setClient(composite);
}
- public static class SetVarCommand extends ServerCommand {
+ public class SetUserCommand extends SetVarCommand {
+ public SetUserCommand(IServerWorkingCopy server) {
+ super(server, "Change Username", nameText, nameText.getText(),
+ JBossServer.SERVER_USERNAME, nameModifyListener);
+ }
+ }
+
+ public class SetPassCommand extends SetVarCommand {
+ public SetPassCommand(IServerWorkingCopy server) {
+ super(server, "Change Password", passText, passText.getText(),
+ JBossServer.SERVER_PASSWORD, passModifyListener);
+ }
+ }
+
+ public class SetVarCommand extends ServerCommand {
private String oldVal;
private String newVal;
private String key;
private Text text;
+ private ModifyListener listener;
- public SetVarCommand(IServerWorkingCopy wc, Text text, String newVal, String
attributeKey) {
- super(wc, "SetVarCommand");
+ public SetVarCommand(IServerWorkingCopy wc, String name,
+ Text text, String newVal, String attributeKey,
+ ModifyListener listener) {
+ super(wc, name);
this.text = text;
this.key = attributeKey;
this.newVal = newVal;
- if( wc instanceof ServerWorkingCopy ) {
- this.oldVal = ((ServerWorkingCopy)wc).getAttribute(attributeKey, "");
- }
+ this.listener = listener;
+ this.oldVal = helper.getAttribute(attributeKey, "");
}
public void execute() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(key, newVal);
+ helper.setAttribute(key, newVal);
}
public void undo() {
- if( server instanceof ServerWorkingCopy )
- ((ServerWorkingCopy)server).setAttribute(key, oldVal);
+ text.removeModifyListener(listener);
+ helper.setAttribute(key, oldVal);
text.setText(oldVal);
+ text.addModifyListener(listener);
}
}
-
}
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/views/server/preferencepages/JBossServersPreferencePage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/views/server/preferencepages/JBossServersPreferencePage.java 2008-05-19
20:06:09 UTC (rev 8201)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/views/server/preferencepages/JBossServersPreferencePage.java 2008-05-19
23:45:48 UTC (rev 8202)
@@ -1,530 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.tools.as.wst.server.ui.views.server.preferencepages;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-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.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Spinner;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.wst.server.core.internal.ServerType;
-import org.eclipse.wst.server.ui.ServerUICore;
-import org.jboss.ide.eclipse.as.core.ExtensionManager;
-import org.jboss.ide.eclipse.as.core.server.IServerPollingAttributes;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ui.Messages;
-
-/**
- *
- * @author Rob Stryker <rob.stryker(a)redhat.com>
- *
- */
-public class JBossServersPreferencePage extends PreferencePage implements
- IWorkbenchPreferencePage {
-
- // for the main section
- private JBossServer currentServer;
- private Table serverTable;
- private TableViewer serverTableViewer;
- private HashMap<JBossServer, ServerAttributeHelper> workingCoppies;
- private Group serverGroup, secondGroup;
- private PageBook book;
- private ServerPreferenceProvider[] groups;
- int pageColumn = 55;
-
- public JBossServersPreferencePage() {
- super();
- }
-
- public JBossServersPreferencePage(String title) {
- super(title);
- }
-
- public JBossServersPreferencePage(String title, ImageDescriptor image) {
- super(title, image);
- }
-
- protected Control createContents(Composite parent) {
- Composite main = new Composite(parent, SWT.BORDER);
- main.setLayout(new FormLayout());
- createServerViewer(main);
- createSecondGroup(main);
- addListeners();
- return main;
- }
-
-
- protected void createServerViewer(Composite main) {
-
- serverGroup = new Group(main, SWT.NONE);
- FillLayout serverGroupLayout = new FillLayout();
- serverGroupLayout.marginHeight = 5;
- serverGroupLayout.marginWidth = 5;
- serverGroup.setLayout(serverGroupLayout);
- serverGroup.setText("Servers");
-
- workingCoppies = new HashMap<JBossServer, ServerAttributeHelper>();
-
- serverTable = new Table(serverGroup, SWT.BORDER);
- FormData lData = new FormData();
- lData.left = new FormAttachment(0,5);
- lData.right = new FormAttachment(100,-5);
- lData.top = new FormAttachment(0,5);
- lData.bottom = new FormAttachment(30,-5);
- serverGroup.setLayoutData(lData);
-
- serverTableViewer = new TableViewer(serverTable);
- serverTableViewer.setContentProvider(new IStructuredContentProvider() {
-
- public Object[] getElements(Object inputElement) {
- return ServerConverter.getAllJBossServers();
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- });
- serverTableViewer.setLabelProvider(new ITableLabelProvider() {
-
- public Image getColumnImage(Object element, int columnIndex) {
- if( element instanceof JBossServer ) {
- return
ServerUICore.getLabelProvider().getImage(((JBossServer)element).getServer());
- }
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if( element instanceof JBossServer ) return
((JBossServer)element).getServer().getName();
- return element.toString();
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
- public void dispose() {
- }
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
- public void removeListener(ILabelProviderListener listener) {
- }
- });
-
- serverTableViewer.setInput("");
-
- }
-
- protected void createSecondGroup(Composite main) {
- secondGroup = new Group(main, SWT.NONE);
-
- FormData lData = new FormData();
- lData.left = new FormAttachment(0,5);
- lData.right = new FormAttachment(100,-5);
- lData.top = new FormAttachment(serverGroup,5);
- lData.bottom = new FormAttachment(100,-5);
- secondGroup.setLayoutData(lData);
-
-
-
- secondGroup.setLayout(new FillLayout());
- book = new PageBook(secondGroup, SWT.NONE);
- groups = new ServerPreferenceProvider[] {
- new TimeoutComposite(book)
- };
- book.showPage(groups[0]);
- secondGroup.setText(groups[0].getName());
- }
-
-
-
- private void addListeners() {
- serverTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection sel = (IStructuredSelection)serverTableViewer.getSelection();
- serverSelected(sel.getFirstElement() == null ? null :
(JBossServer)sel.getFirstElement());
- }
- });
- }
-
- private void serverSelected(JBossServer server) {
- currentServer = server;
- ServerAttributeHelper wcHelper = getWCHelper(server);
- for( int i = 0; i < groups.length; i++ ) {
- try {
- groups[i].serverSelected(server, wcHelper);
- } catch( Exception e ) {}
- }
- }
-
-
- private ServerAttributeHelper getWCHelper(JBossServer server) {
- if( workingCoppies.get(server) == null ) {
- ServerAttributeHelper ret = server.getAttributeHelper();
- workingCoppies.put(server, ret);
- return ret;
- }
-
- return workingCoppies.get(server);
- }
-
- private ServerAttributeHelper getSelectedWC() {
- return currentServer == null ? null : getWCHelper(currentServer);
- }
-
- public void init(IWorkbench workbench) {
- }
-
- public boolean performOk() {
- super.performOk();
- saveDirtyWorkingCoppies();
- return true;
- }
-
- /* Saves the actual ServerWorkingCopy changes into the IServer it relates to. */
- private void saveDirtyWorkingCoppies() {
- Collection<ServerAttributeHelper> c = workingCoppies.values();
- Iterator<ServerAttributeHelper> i = c.iterator();
- Object o;
- while(i.hasNext()) {
- o = i.next();
- if( o instanceof ServerAttributeHelper) {
- ServerAttributeHelper o2 = (ServerAttributeHelper)o;
- if( o2.isDirty() ) {
- try {
- o2.save(true, new NullProgressMonitor());
- } catch( CoreException ce) {
- ce.printStackTrace();
- }
- }
- }
- }
- }
-
- public static abstract class ServerPreferenceProvider extends Composite {
- protected String name;
- public ServerPreferenceProvider(Composite parent, int style,
- String name) {
- super(parent, style);
- this.name = name;
- }
- public String getName() { return name; }
- public abstract void serverSelected(JBossServer server, ServerAttributeHelper
helper);
- }
-
- public static class TimeoutComposite extends ServerPreferenceProvider {
-
- private Spinner stopSpinner, startSpinner;
- private Button abortOnTimeout, ignoreOnTimeout;
- private JBossServer server;
- private ServerAttributeHelper helper;
- private Composite durations, behavior, pollers;
-
- // polling
- private Combo startPollerCombo, stopPollerCombo;
- private String[] startupTypesStrings, shutdownTypesStrings;
- ServerStatePollerType[] startupTypes, shutdownTypes;
-
- public TimeoutComposite(Composite parent) {
- super(parent, SWT.NONE, Messages.PreferencePageServerTimeouts);
-
- findPossiblePollers();
-
- setLayout(new FormLayout());
- createTimeoutDurations();
- createTimeoutBehavior();
- createPollerChoices();
-
- durations.setLayoutData(createLayoutData(null));
- behavior.setLayoutData(createLayoutData(durations));
- pollers.setLayoutData(createLayoutData(behavior));
- addTimeoutListeners();
- }
-
- protected void findPossiblePollers() {
- startupTypes = ExtensionManager.getDefault().getStartupPollers();
- shutdownTypes = ExtensionManager.getDefault().getShutdownPollers();
- startupTypesStrings = new String[startupTypes.length];
- shutdownTypesStrings = new String[shutdownTypes.length];
-
- for( int i = 0; i < startupTypes.length; i++ ) {
- startupTypesStrings[i] = startupTypes[i].getName();
- }
- for( int i = 0; i < shutdownTypes.length; i++ ) {
- shutdownTypesStrings[i] = shutdownTypes[i].getName();
- }
- }
-
- private FormData createLayoutData(Composite top) {
- FormData data = new FormData();
- if( top == null ) data.top = new FormAttachment(0,5);
- else data.top = new FormAttachment(top, 5);
- data.left = new FormAttachment(0,5);
- data.right = new FormAttachment(100,-5);
- return data;
- }
- public void serverSelected(JBossServer server,
- ServerAttributeHelper helper) {
- this.server = server;
- this.helper = helper;
- timeoutServerSelected();
- }
-
- protected void createTimeoutDurations() {
- durations = new Composite(this, SWT.NONE);
- durations.setLayout(new FormLayout());
-
- // add two textboxes, two labels
- Label startTimeoutLabel, stopTimeoutLabel;
-
- startTimeoutLabel = new Label(durations, SWT.NONE);
- stopTimeoutLabel = new Label(durations, SWT.NONE);
-
- stopSpinner = new Spinner(durations, SWT.BORDER);
- startSpinner = new Spinner(durations, SWT.BORDER);
-
- FormData startTD = new FormData();
- startTD.left = new FormAttachment(0,5);
- startTD.top = new FormAttachment(0,7);
- startTimeoutLabel.setLayoutData(startTD);
- startTimeoutLabel.setText(Messages.PreferencePageStartTimeouts);
-
- FormData stopTD = new FormData();
- stopTD.left = new FormAttachment(0,5);
- stopTD.top = new FormAttachment(startSpinner,7);
- stopTimeoutLabel.setLayoutData(stopTD);
- stopTimeoutLabel.setText(Messages.PreferencePageStopTimeouts);
-
- durations.layout();
- int startWidth = startTimeoutLabel.getSize().x;
- int stopWidth = stopTimeoutLabel.getSize().x;
-
- Label widest = startWidth > stopWidth ? startTimeoutLabel : stopTimeoutLabel;
-
- FormData startD = new FormData();
- startD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
- startD.right = new FormAttachment(100, -5);
- startD.top = new FormAttachment(0,5);
- startSpinner.setLayoutData(startD);
-
- FormData stopD = new FormData();
- stopD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
- stopD.right = new FormAttachment(100, -5);
- stopD.top = new FormAttachment(startSpinner,5);
- stopSpinner.setLayoutData(stopD);
-
-
- stopSpinner.setMinimum(0);
- startSpinner.setMinimum(0);
- stopSpinner.setIncrement(1);
- startSpinner.setIncrement(1);
- stopSpinner.setEnabled(false);
- startSpinner.setEnabled(false);
-
- }
-
- protected void createTimeoutBehavior() {
- behavior = new Composite(this, SWT.NONE);
- behavior.setLayout(new FormLayout());
-
- Label uponTimeoutLabel = new Label(behavior, SWT.NONE);
- abortOnTimeout = new Button(behavior, SWT.RADIO);
- ignoreOnTimeout = new Button(behavior, SWT.RADIO);
-
- FormData utl = new FormData();
- utl.left = new FormAttachment(0,5);
- utl.right = new FormAttachment(100, -5);
- utl.top = new FormAttachment(0,5);
- uponTimeoutLabel.setLayoutData(utl);
-
- FormData b1D = new FormData();
- b1D.left = new FormAttachment(0,15);
- b1D.right = new FormAttachment(100, -5);
- b1D.top = new FormAttachment(uponTimeoutLabel,5);
- abortOnTimeout.setLayoutData(b1D);
-
- FormData b2D = new FormData();
- b2D.left = new FormAttachment(0,15);
- b2D.right = new FormAttachment(100, -5);
- b2D.top = new FormAttachment(abortOnTimeout,5);
- ignoreOnTimeout.setLayoutData(b2D);
-
- uponTimeoutLabel.setText(Messages.PreferencePageUponTimeout);
- abortOnTimeout.setText(Messages.PreferencePageUponTimeoutAbort);
- ignoreOnTimeout.setText(Messages.PreferencePageUponTimeoutIgnore);
- abortOnTimeout.setEnabled(false);
- ignoreOnTimeout.setEnabled(false);
-
- }
-
- protected void createPollerChoices() {
- pollers = new Composite(this, SWT.NONE);
- pollers.setLayout(new GridLayout(2, false));
-
- // create widgets
- Label start, stop;
- start = new Label(pollers, SWT.NONE);
- startPollerCombo = new Combo(pollers, SWT.READ_ONLY);
- stop = new Label(pollers, SWT.NONE);
- stopPollerCombo = new Combo(pollers, SWT.READ_ONLY);
-
- start.setText("Startup Poller");
- stop.setText("Shutdown Poller");
-
- // set items
- startPollerCombo.setItems(startupTypesStrings);
- stopPollerCombo.setItems(shutdownTypesStrings);
-
- startPollerCombo.setEnabled(false);
- stopPollerCombo.setEnabled(false);
- }
-
- private void addTimeoutListeners() {
- startSpinner.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.START_TIMEOUT,
startSpinner.getSelection() * 1000);
- }
- });
- stopSpinner.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.STOP_TIMEOUT,
stopSpinner.getSelection() * 1000);
- }
- });
-
- abortOnTimeout.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_ABORT);
- }
- });
- ignoreOnTimeout.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
- }
- });
- startPollerCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.STARTUP_POLLER_KEY,
startupTypes[startPollerCombo.getSelectionIndex()].getId());
- }
- });
- stopPollerCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( helper != null )
- helper.setAttribute(IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
shutdownTypes[stopPollerCombo.getSelectionIndex()].getId());
- }
- });
- }
-
- private void timeoutServerSelected() {
- // Handle spinners
- startSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStartTimeout()
/ 1000);
- stopSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStopTimeout()
/ 1000);
- startSpinner.setSelection(getStartTimeout(helper));
- stopSpinner.setSelection(getStopTimeout(helper));
-
- startSpinner.setEnabled(true);
- stopSpinner.setEnabled(true);
- abortOnTimeout.setEnabled(true);
- ignoreOnTimeout.setEnabled(true);
-
- boolean currentVal = helper.getAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
- if( currentVal == IServerPollingAttributes.TIMEOUT_ABORT) {
- abortOnTimeout.setSelection(true);
- ignoreOnTimeout.setSelection(false);
- } else {
- abortOnTimeout.setSelection(false);
- ignoreOnTimeout.setSelection(true);
- }
-
- // poller
- stopPollerCombo.setEnabled(true);
- startPollerCombo.setEnabled(true);
- String currentStartId =
helper.getAttribute(IServerPollingAttributes.STARTUP_POLLER_KEY,
IServerPollingAttributes.DEFAULT_STARTUP_POLLER);
- String currentStopId =
helper.getAttribute(IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
IServerPollingAttributes.DEFAULT_SHUTDOWN_POLLER);
- startPollerCombo.select(startPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStartId).getName()));
- stopPollerCombo.select(stopPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStopId).getName()));
- }
-
- public int getStartTimeout(ServerAttributeHelper helper) {
- int prop = helper.getAttribute(IServerPollingAttributes.START_TIMEOUT, -1);
- int max = ((ServerType)helper.getServer().getServerType()).getStartTimeout();
-
- if( prop <= 0 || prop > max ) return max / 1000;
- return prop / 1000;
- }
- public int getStopTimeout(ServerAttributeHelper helper) {
- int prop = helper.getAttribute(IServerPollingAttributes.STOP_TIMEOUT, -1);
- int max = ((ServerType)helper.getServer().getServerType()).getStopTimeout();
-
- if( prop <= 0 || prop > max ) return max / 1000;
- return prop / 1000;
- }
- }
-}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-05-19 20:06:09 UTC (rev
8201)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-05-19 23:45:48 UTC (rev
8202)
@@ -95,11 +95,6 @@
<extension
point="org.eclipse.ui.preferencePages">
- <page
- category="org.eclipse.wst.server.ui.preferencePage"
-
class="org.jboss.tools.as.wst.server.ui.views.server.preferencepages.JBossServersPreferencePage"
- id="org.jboss.ide.eclipse.as.ui.jbossServerPreferencePage"
- name="JBoss Servers"/>
<page
category="org.eclipse.wst.server.ui.preferencePage"
@@ -233,11 +228,17 @@
point="org.eclipse.wst.server.ui.editorPageSections">
<section
class="org.jboss.ide.eclipse.as.ui.editor.DeploySection"
- id="org.jboss.ide.eclipse.as.ui.exitor.deployServer.deployDir"
+ id="org.jboss.ide.eclipse.as.ui.editor.deployServer.deployDir"
insertionId="org.eclipse.wst.server.editor.overview.left"
order="10"
typeIds="org.jboss.ide.eclipse.as.systemCopyServer,
org.jboss.ide.eclipse.as.32, org.jboss.ide.eclipse.as.40, org.jboss.ide.eclipse.as.42,
org.jboss.ide.eclipse.as.50"/>
<section
+ class="org.jboss.ide.eclipse.as.ui.editor.PollerSection"
+ id="org.jboss.ide.eclipse.as.ui.editor.pollerSection"
+ insertionId="org.eclipse.wst.server.editor.overview.right"
+ order="10"
+ typeIds="org.jboss.ide.eclipse.as.systemCopyServer,
org.jboss.ide.eclipse.as.32, org.jboss.ide.eclipse.as.40, org.jboss.ide.eclipse.as.42,
org.jboss.ide.eclipse.as.50"/>
+ <section
class="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection"
id="org.jboss.ide.eclipse.as.ui.editor.passwordSection"
insertionId="org.eclipse.wst.server.editor.overview.left"