Author: rob.stryker(a)jboss.com
Date: 2008-09-02 16:53:46 -0400 (Tue, 02 Sep 2008)
New Revision: 10038
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ChangePortDialog.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/ServerEditorPortSection.exsd
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
Log:
JBIDE-2235 - fixing server editor / port section
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2008-09-02
18:45:08 UTC (rev 10037)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2008-09-02
20:53:46 UTC (rev 10038)
@@ -232,7 +232,22 @@
public static String EditorChangeWebCommandName;
public static String EditorChangeUsernameCommandName;
public static String EditorChangePasswordCommandName;
+ public static String EditorCPD_Name;
+ public static String EditorCPD_XPath;
+ public static String EditorCPD_Attribute;
+ public static String EditorCPD_Count;
+ public static String EditorCPD_Value;
+ public static String EditorCPD_Location;
+ public static String EditorCPD_Default;
+ public static String EditorCPD_NoDefault;
+ public static String EditorCPD_SelectionDetails;
+ public static String EditorCPD_DefaultShellTitle;
+ public static String EditorCPD_DefaultDescription;
+
+
+ public static String Customize;
+
// misc
public static String ServerSaveFailed;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2008-09-02
18:45:08 UTC (rev 10037)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2008-09-02
20:53:46 UTC (rev 10038)
@@ -205,13 +205,25 @@
EditorChangeStopPollerCommandName=Change Shutdown Poller
EditorServerPorts=Server Ports
EditorServerPortsDescription=The ports entered here are which ports the tools\nwill poll
the server on. Changing these fields\nwill not change the ports the server itself listens
on.
-EditorJNDIPort=JNDI Port:
-EditorWebPort=Web Port:
+EditorJNDIPort=JNDI Port
+EditorWebPort=Web Port
EditorAutomaticallyDetectPort=Automatically detect
EditorChangeJNDICommandName=Change JNDI Port Details
EditorChangeWebCommandName=Change Web Port Details
EditorChangeUsernameCommandName=Change Username
EditorChangePasswordCommandName=Change Password
+EditorCPD_Name=Name
+EditorCPD_XPath=XPath Pattern
+EditorCPD_Attribute=Attribute Name
+EditorCPD_Count=Number of Matches
+EditorCPD_Value=First Value
+EditorCPD_Location=File of first match
+EditorCPD_Default=The default xpath for {0} is "{1}".
+EditorCPD_NoDefault=There is no default xpath for {0}.
+EditorCPD_SelectionDetails=Selection Details
+EditorCPD_DefaultShellTitle=Edit Port
+EditorCPD_DefaultDescription=This wizard allows you to edit which xpath is used to locate
a port used by the tooling.\nThis will not change any server files, only what ports are
used to interact with it.
+Customize=Customize...
# misc
ServerSaveFailed=Server save failed
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ChangePortDialog.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ChangePortDialog.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/ChangePortDialog.java 2008-09-02
20:53:46 UTC (rev 10038)
@@ -0,0 +1,244 @@
+package org.jboss.ide.eclipse.as.ui.dialogs;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathCategory;
+import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathFileResult;
+import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathModel;
+import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathQuery;
+import org.jboss.ide.eclipse.as.ui.Messages;
+
+public class ChangePortDialog extends TitleAreaDialog {
+
+ public static class ChangePortDialogInfo {
+ public String port;
+ public String defaultValue;
+ public String shellTitle;
+ public String description;
+ public IServer server;
+ public String currentXPath;
+ }
+
+ private ChangePortDialogInfo info;
+ private String selected;
+ private XPathQuery currentQuery;
+ private boolean queriesLoaded = false;
+ private List listWidget;
+ private Group group;
+ private Label nameLabel; private Text nameValueLabel;
+ private Label xpathLabel; private Text xpathValueLabel;
+ private Label attributeLabel; private Text attributeValueLabel;
+ private Label locationLabel; private Text locationValueLabel;
+ private Label countLabel; private Text countValueLabel;
+ private Label valueLabel; private Text valueValueLabel;
+
+
+ public ChangePortDialog(Shell parentShell, ChangePortDialogInfo info) {
+ super(parentShell);
+ this.info = info;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite c = (Composite)super.createDialogArea(parent);
+ Composite main = new Composite(c, SWT.BORDER);
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+ main.setLayout(new FormLayout());
+ createUI(main);
+ fillWidgets();
+ addListeners();
+ setTitle(info.port);
+ setMessage(info.description != null ? info.description
+ : Messages.EditorCPD_DefaultDescription);
+ getShell().setText(info.shellTitle != null ? info.shellTitle
+ : Messages.EditorCPD_DefaultShellTitle);
+ return c;
+ }
+
+ protected void createUI(Composite main) {
+ listWidget = new List(main, SWT.DEFAULT);
+ FormData d = new FormData();
+ d.top = new FormAttachment(0,5);
+ d.left = new FormAttachment(0,5);
+ d.bottom = new FormAttachment(100,-5);
+ d.right = new FormAttachment(0,150);
+ listWidget.setLayoutData(d);
+
+ Label defaultLabel = new Label(main, SWT.NONE);
+ d = new FormData();
+ d.right = new FormAttachment(100,-5);
+ d.left = new FormAttachment(listWidget,5);
+ d.bottom = new FormAttachment(100,-5);
+ defaultLabel.setLayoutData(d);
+
+ group = new Group(main, SWT.DEFAULT);
+ d = new FormData();
+ d.right = new FormAttachment(100,-5);
+ d.left = new FormAttachment(listWidget,5);
+ d.bottom = new FormAttachment(defaultLabel,-5);
+ d.top = new FormAttachment(0,5);
+ group.setLayoutData(d);
+
+ GridLayout gl = new GridLayout(2, false);
+ gl.marginRight = 5;
+ group.setLayout(gl);
+ GridData common = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+ nameLabel = new Label(group, SWT.NONE);
+ nameValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+ xpathLabel = new Label(group, SWT.NONE);
+ xpathValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+ attributeLabel = new Label(group, SWT.NONE);
+ attributeValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+ countLabel = new Label(group, SWT.NONE);
+ countValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+ valueLabel = new Label(group, SWT.NONE);
+ valueValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+ locationLabel = new Label(group, SWT.NONE);
+ locationValueLabel = new Text(group, SWT.DEFAULT | SWT.H_SCROLL);
+
+ nameValueLabel.setLayoutData(common);
+ xpathValueLabel.setLayoutData(common);
+ attributeValueLabel.setLayoutData(common);
+ countValueLabel.setLayoutData(common);
+ valueValueLabel.setLayoutData(common);
+ locationValueLabel.setLayoutData(common);
+
+ nameLabel.setText(Messages.EditorCPD_Name);
+ xpathLabel.setText(Messages.EditorCPD_XPath);
+ attributeLabel.setText(Messages.EditorCPD_Attribute);
+ countLabel.setText(Messages.EditorCPD_Count);
+ valueLabel.setText(Messages.EditorCPD_Value);
+ locationLabel.setText(Messages.EditorCPD_Location);
+ String defaultLabelText;
+ if( info.defaultValue != null )
+ defaultLabelText = NLS.bind(Messages.EditorCPD_Default, info.port,
info.defaultValue);
+ else
+ defaultLabelText = NLS.bind(Messages.EditorCPD_NoDefault, info.port);
+ defaultLabel.setText(defaultLabelText);
+ group.setText(Messages.EditorCPD_SelectionDetails);
+ }
+
+ protected void fillWidgets() {
+ ArrayList<String> list = new ArrayList<String>();
+ XPathCategory[] categories = XPathModel.getDefault().getCategories(info.server);
+ for( int i = 0; i < categories.length; i++ ) {
+ XPathQuery[] queries = categories[i].getQueries();
+ for( int j = 0; j < queries.length; j++ ) {
+ list.add(categories[i].getName() + IPath.SEPARATOR + queries[j].getName());
+ }
+ }
+ String[] stuff = (String[]) list.toArray(new String[list.size()]);
+ listWidget.setItems(stuff);
+ for( int i = 0; i < stuff.length; i++ )
+ if( stuff[i] == info.currentXPath)
+ listWidget.select(i);
+ }
+
+ protected void addListeners() {
+ listWidget.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ selectionChanged();
+ } });
+ }
+
+ protected synchronized void selectionChanged() {
+ if( !queriesLoaded ) {
+ try {
+ final String[] items = listWidget.getItems();
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ dialog.run(true, false, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ monitor.beginTask("Loading...", items.length);
+ for( int i = 0; i < items.length; i++ ) {
+ countMatches(currentQuery);
+ monitor.worked(1);
+ }
+ monitor.done();
+ queriesLoaded = true;
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ selectionChanged2();
+ }
+ });
+ } });
+ } catch( InvocationTargetException ite) {
+ ite.printStackTrace();
+ } catch(InterruptedException ie ) {
+ ie.printStackTrace();
+ }
+ } else {
+ selectionChanged2();
+ }
+ }
+
+ private void selectionChanged2() {
+ currentQuery = null;
+ int s = listWidget.getSelectionIndex();
+ if( s != -1 ) {
+ selected = listWidget.getItem(s);
+ currentQuery = XPathModel.getDefault().getQuery(info.server, new Path(selected));
+ }
+ if(currentQuery != null) {
+ nameValueLabel.setText(safeString(currentQuery.getName()));
+ xpathValueLabel.setText(safeString(currentQuery.getXpathPattern()));
+ attributeValueLabel.setText(safeString(currentQuery.getAttribute()));
+ locationValueLabel.setText(safeString(currentQuery.getBaseDir()));
+ countValueLabel.setText(countMatches(currentQuery));
+ valueValueLabel.setText(safeString(currentQuery.getFirstResult()));
+ } else {
+ nameValueLabel.setText(safeString(null));
+ xpathValueLabel.setText(safeString(null));
+ attributeValueLabel.setText(safeString(null));
+ locationValueLabel.setText(safeString(null));
+ countValueLabel.setText(safeString(null));
+ valueValueLabel.setText(safeString(null));
+ }
+ }
+
+ private String countMatches(XPathQuery query) {
+ if( query == null )
+ return new Integer(-1).toString();
+
+ int count = 0;
+ XPathFileResult[] fResults = query.getResults();
+ for( int i = 0; i < fResults.length; i++ ) {
+ count += fResults[i].getChildren().length;
+ }
+ return new Integer(count).toString();
+ }
+ private String safeString(String s) {
+ return s == null ? "" : s;
+ }
+
+ public String getSelection() {
+ return selected;
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java 2008-09-02
18:45:08 UTC (rev 10037)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java 2008-09-02
20:53:46 UTC (rev 10038)
@@ -1,19 +1,26 @@
package org.jboss.ide.eclipse.as.ui.editor;
import java.util.ArrayList;
+import java.util.HashMap;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
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.Event;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
@@ -29,7 +36,10 @@
import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathQuery;
import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.dialogs.ChangePortDialog;
+import org.jboss.ide.eclipse.as.ui.dialogs.ChangePortDialog.ChangePortDialogInfo;
/**
*
@@ -37,11 +47,23 @@
*
*/
public class PortSection extends ServerEditorSection {
+
+ /* Load the various port editor pieces */
+ private static ArrayList<IPortEditorExtension> sectionList = new
ArrayList<IPortEditorExtension>();
+ static {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf =
registry.getConfigurationElementsFor(JBossServerUIPlugin.PLUGIN_ID,
"ServerEditorPortSection");
+ for( int i = 0; i < cf.length; i++ ) {
+ try {
+ Object o = cf[i].createExecutableExtension("class");
+ if( o != null && o instanceof IPortEditorExtension)
+ sectionList.add((IPortEditorExtension)o);
+ } catch( CoreException ce) { /* ignore */ }
+ }
+ }
+
+
protected ServerAttributeHelper helper;
- protected Label jndiLabel, webLabel;
- protected Text jndiText, webText;
- protected Button jndiDetect, webDetect;
- protected Combo jndiDetectCombo, webDetectCombo;
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
@@ -51,53 +73,177 @@
public void createSection(Composite parent) {
super.createSection(parent);
createUI(parent);
- initializeState();
- addListeners();
}
+
+ public static interface IPortEditorExtension {
+ public void setServerAttributeHelper(ServerAttributeHelper helper);
+ public void setSection(ServerEditorSection section);
+ public Control createControl(Composite parent);
+ }
- protected void initializeState() {
- boolean detectJNDI = helper.getAttribute(IJBossServerConstants.JNDI_PORT_DETECT,
true);
- jndiDetect.setSelection(detectJNDI);
- jndiDetectCombo.setEnabled(detectJNDI);
- jndiText.setEnabled(!detectJNDI);
- jndiText.setEditable(!detectJNDI);
- String jndiXPath = helper.getAttribute(IJBossServerConstants.JNDI_PORT_DETECT_XPATH,
IJBossServerConstants.JNDI_PORT_DEFAULT_XPATH.toString());
- int index = jndiDetectCombo.indexOf(jndiXPath);
- if( index != -1 ) {
- jndiDetectCombo.select(index);
- if( detectJNDI )
- jndiText.setText(findPort(new Path(jndiXPath)));
- else
- jndiText.setText(helper.getAttribute(IJBossServerConstants.JNDI_PORT,
""));
+ public static class JNDIPortEditorExtension extends PortEditorExtension {
+ public JNDIPortEditorExtension() {
+ super(Messages.EditorJNDIPort, IJBossServerConstants.JNDI_PORT_DETECT_XPATH,
+ IJBossServerConstants.JNDI_PORT_DETECT,
+ IJBossServerConstants.JNDI_PORT_DEFAULT_XPATH);
}
+ public ServerCommand getCommand() {
+ return new SetPortCommand(helper.getWorkingCopy(), helper,
Messages.EditorChangeJNDICommandName,
+ IJBossServerConstants.JNDI_PORT, IJBossServerConstants.JNDI_PORT_DETECT,
+ IJBossServerConstants.JNDI_PORT_DETECT_XPATH,
IJBossServerConstants.JNDI_PORT_DEFAULT_XPATH,
+ text, detect, currentXPath, listener);
+ }
+ protected ChangePortDialogInfo getDialogInfo() {
+ ChangePortDialogInfo info = new ChangePortDialogInfo();
+ info.port = Messages.EditorJNDIPort;
+ info.defaultValue = IJBossServerConstants.JNDI_PORT_DEFAULT_XPATH;
+ info.server = helper.getWorkingCopy().getOriginal();
+ info.currentXPath = currentXPath;
+ return info;
+ }
+ }
+
+ public static class WebPortEditorExtension extends PortEditorExtension {
+ public WebPortEditorExtension() {
+ super(Messages.EditorWebPort, IJBossServerConstants.WEB_PORT_DETECT_XPATH,
+ IJBossServerConstants.WEB_PORT_DETECT,
+ IJBossServerConstants.WEB_PORT_DEFAULT_XPATH);
+ }
+
+ public ServerCommand getCommand() {
+ return new SetPortCommand(helper.getWorkingCopy(), helper,
Messages.EditorChangeWebCommandName,
+ IJBossServerConstants.WEB_PORT, IJBossServerConstants.WEB_PORT_DETECT,
+ IJBossServerConstants.WEB_PORT_DETECT_XPATH,
IJBossServerConstants.WEB_PORT_DEFAULT_XPATH,
+ text, detect, currentXPath, listener);
+ }
+ protected ChangePortDialogInfo getDialogInfo() {
+ ChangePortDialogInfo info = new ChangePortDialogInfo();
+ info.port = Messages.EditorWebPort;
+ info.defaultValue = IJBossServerConstants.WEB_PORT_DEFAULT_XPATH;
+ info.server = helper.getWorkingCopy().getOriginal();
+ info.currentXPath = currentXPath;
+ return info;
+ }
+ }
+
+ public static abstract class PortEditorExtension implements IPortEditorExtension {
+ protected Button detect;
+ protected Text text;
+ protected Label label;
+ protected Link link;
+ protected String labelText, currentXPathKey, detectXPathKey, defaultXPath;
+ protected String currentXPath;
+ protected ServerAttributeHelper helper;
+ protected Listener listener;
+ protected ServerEditorSection section;
+ public PortEditorExtension(String labelText, String currentXPathKey, String
detectXPathKey, String defaultXPath) {
+ this.labelText = labelText;
+ this.currentXPathKey = currentXPathKey;
+ this.detectXPathKey = detectXPathKey;
+ this.defaultXPath = defaultXPath;
+ }
+ public void setServerAttributeHelper(ServerAttributeHelper helper) {
+ this.helper = helper;
+ }
+ public void setSection(ServerEditorSection section) {
+ this.section = section;
+ }
+ public Control createControl(Composite parent) {
+ Control c = createUI(parent);
+ initialize();
+ addListeners();
+ return c;
+ }
- boolean detectWeb = helper.getAttribute(IJBossServerConstants.WEB_PORT_DETECT, true);
- webDetect.setSelection(detectWeb);
- webDetectCombo.setEnabled(detectWeb);
- webText.setEnabled(!detectWeb);
- webText.setEditable(!detectWeb);
- String webXPath = helper.getAttribute(IJBossServerConstants.WEB_PORT_DETECT_XPATH,
IJBossServerConstants.WEB_PORT_DEFAULT_XPATH.toString());
- int index2 = webDetectCombo.indexOf(webXPath);
- if( index2 != -1 ) {
- webDetectCombo.select(index2);
- if( detectWeb )
- webText.setText(findPort(new Path(webXPath)));
+ protected Control createUI(Composite parent) {
+ Composite child = new Composite(parent, SWT.NONE);
+ child.setLayout(new FormLayout());
+ label = new Label(child, SWT.NONE);
+ text = new Text(child, SWT.DEFAULT);
+ detect = new Button(child, SWT.CHECK);
+ link = new Link(child, SWT.DEFAULT);
+
+ FormData data;
+ data = new FormData();
+ data.top = new FormAttachment(0,8);
+ data.right = new FormAttachment(100,-5);
+ link.setLayoutData(data);
+
+ data = new FormData();
+ data.right = new FormAttachment(link, -5);
+ data.top = new FormAttachment(0,5);
+ detect.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(detect, -200);
+ data.right = new FormAttachment(detect, -5);
+ data.top = new FormAttachment(0,5);
+ text.setLayoutData(data);
+
+ data = new FormData();
+ data.right = new FormAttachment(text,-5);
+ data.top = new FormAttachment(0,8);
+ label.setLayoutData(data);
+
+ label.setText(labelText);
+ detect.setText(Messages.EditorAutomaticallyDetectPort);
+ link.setText("<a href=\"\">" + Messages.Customize +
"</a>");
+ return child;
+ }
+ protected void initialize() {
+ boolean shouldDetect = helper.getAttribute(detectXPathKey, true);
+ detect.setSelection(shouldDetect);
+ text.setEnabled(!shouldDetect);
+ text.setEditable(!shouldDetect);
+ currentXPath = helper.getAttribute(currentXPathKey, defaultXPath);
+ if( shouldDetect )
+ text.setText(findPort(new Path(currentXPath)));
else
- webText.setText(helper.getAttribute(IJBossServerConstants.WEB_PORT, ""));
+ text.setText(helper.getAttribute(IJBossServerConstants.JNDI_PORT, ""));
}
- }
-
- protected String findPort(IPath path) {
- XPathQuery query = XPathModel.getDefault().getQuery(server.getOriginal(), path);
- if(query!=null) {
- String result = query.getFirstResult();
- if( result != null ) {
- return result;
+ protected void addListeners() {
+ listener = new Listener() {
+ public void handleEvent(Event event) {
+ section.execute(getCommand());
+ }
+ };
+ text.addListener(SWT.Modify, listener);
+ detect.addListener(SWT.Selection, listener);
+ link.addListener(SWT.Selection, createLinkListener());
+ }
+
+ protected Listener createLinkListener() {
+ return new Listener() {
+ public void handleEvent(Event event) {
+ ChangePortDialog dialog = getDialog();
+ int result = dialog.open();
+ if( result == Dialog.OK) {
+ currentXPath = dialog.getSelection();
+ section.execute(getCommand());
+ text.setFocus();
+ }
+ }
+ };
+ }
+ public ChangePortDialog getDialog() {
+ return new ChangePortDialog(section.getShell(), getDialogInfo());
+ }
+ protected abstract ChangePortDialogInfo getDialogInfo();
+
+ protected String findPort(IPath path) {
+ XPathQuery query = XPathModel.getDefault().getQuery(helper.getServer(), path);
+ if(query!=null) {
+ String result = query.getFirstResult();
+ if( result != null ) {
+ return result;
+ }
}
+ return "-1";
}
- return "-1";
-}
-
+ protected /* abstract */ ServerCommand getCommand() {
+ return null;
+ }
+ }
protected void createUI(Composite parent) {
@@ -110,96 +256,44 @@
composite.setLayout(new FormLayout());
Label description = new Label(composite, SWT.NONE);
description.setText(Messages.EditorServerPortsDescription);
-
- Composite jndiChild = createJNDIUI(composite);
- Composite webChild = createWebUI(composite);
-
FormData data = new FormData();
data.top = new FormAttachment(0,5);
+ data.left = new FormAttachment(0,5);
description.setLayoutData(data);
-
- data = new FormData();
- data.top = new FormAttachment(description, 5);
- jndiChild.setLayoutData(data);
-
- data = new FormData();
- data.top = new FormAttachment(jndiChild, 5);
- webChild.setLayoutData(data);
+ addUIAdditions(composite, description);
toolkit.paintBordersFor(composite);
section.setClient(composite);
}
- protected Composite createJNDIUI(Composite composite) {
- Composite child = new Composite(composite, SWT.NONE);
- child.setLayout(new FormLayout());
- jndiLabel = new Label(child, SWT.NONE);
- jndiText = new Text(child, SWT.DEFAULT);
- jndiDetect = new Button(child, SWT.CHECK);
- jndiDetectCombo = new Combo(child, SWT.DEFAULT);
+ private void addUIAdditions(Composite parent, Control top) {
+ IPortEditorExtension[] extensions = (IPortEditorExtension[]) sectionList.toArray(new
IPortEditorExtension[sectionList.size()]);
- FormData data = new FormData();
- data.left = new FormAttachment(0,5);
- data.top = new FormAttachment(0,5);
- jndiLabel.setLayoutData(data);
-
+ FormData data;
+ Control c;
+ Composite wrapper = new Composite(parent, SWT.NONE);
+ wrapper.setLayout(new FormLayout());
data = new FormData();
- data.left = new FormAttachment(jndiLabel,5);
- data.right = new FormAttachment(jndiLabel, 150);
- data.top = new FormAttachment(0,5);
- jndiText.setLayoutData(data);
-
- data = new FormData();
- data.left = new FormAttachment(jndiText,5);
- data.top = new FormAttachment(0,5);
- jndiDetect.setLayoutData(data);
-
- data = new FormData();
- data.left = new FormAttachment(jndiDetect,5);
- data.top = new FormAttachment(0,5);
- jndiDetectCombo.setLayoutData(data);
-
- jndiLabel.setText(Messages.EditorJNDIPort);
- jndiDetect.setText(Messages.EditorAutomaticallyDetectPort);
- jndiDetectCombo.setItems(getXPathStrings());
- return child;
+ data.top = new FormAttachment(top,0);
+ data.left = new FormAttachment(0,0);
+ wrapper.setLayoutData(data);
+ top = null;
+ for( int i = 0; i < extensions.length; i++ ) {
+ extensions[i].setServerAttributeHelper(helper);
+ extensions[i].setSection(this);
+ c = extensions[i].createControl(wrapper);
+ 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);
+ c.setLayoutData(data);
+ top = c;
+ }
}
- protected Composite createWebUI(Composite composite) {
- Composite child = new Composite(composite, SWT.NONE);
- child.setLayout(new FormLayout());
- webLabel = new Label(child, SWT.NONE);
- webText = new Text(child, SWT.DEFAULT);
- webDetect = new Button(child, SWT.CHECK);
- webDetectCombo = new Combo(child, SWT.DEFAULT);
-
- FormData data = new FormData();
- data.left = new FormAttachment(0,5);
- data.top = new FormAttachment(0,5);
- webLabel.setLayoutData(data);
-
- data = new FormData();
- data.left = new FormAttachment(webLabel,5);
- data.right = new FormAttachment(webLabel, 150);
- data.top = new FormAttachment(0,5);
- webText.setLayoutData(data);
-
- data = new FormData();
- data.left = new FormAttachment(webText,5);
- data.top = new FormAttachment(0,5);
- webDetect.setLayoutData(data);
-
- data = new FormData();
- data.left = new FormAttachment(webDetect,5);
- data.top = new FormAttachment(0,5);
- webDetectCombo.setLayoutData(data);
-
- webLabel.setText(Messages.EditorWebPort);
- webDetect.setText(Messages.EditorAutomaticallyDetectPort);
- webDetectCombo.setItems(getXPathStrings());
- return child;
- }
-
protected String[] getXPathStrings() {
ArrayList<String> list = new ArrayList<String>();
XPathCategory[] categories =
XPathModel.getDefault().getCategories(server.getOriginal());
@@ -212,84 +306,45 @@
return (String[]) list.toArray(new String[list.size()]);
}
- protected Listener jndiListener, webListener;
-
- protected void addListeners() {
- jndiListener = new Listener() {
- public void handleEvent(Event event) {
- execute(new ChangeJNDICommand(server));
- }
- };
- jndiText.addListener(SWT.Modify, jndiListener);
- jndiDetect.addListener(SWT.Selection, jndiListener);
- jndiDetectCombo.addListener(SWT.Modify, jndiListener);
-
- webListener = new Listener() {
- public void handleEvent(Event event) {
- execute(new ChangeWebCommand(server));
- }
- };
- webText.addListener(SWT.Modify, webListener);
- webDetect.addListener(SWT.Selection, webListener);
- webDetectCombo.addListener(SWT.Modify, webListener);
-
- }
-
- public class ChangeJNDICommand extends SetPortCommand {
- public ChangeJNDICommand(IServerWorkingCopy server) {
- super(server, Messages.EditorChangeJNDICommandName,
- IJBossServerConstants.JNDI_PORT, IJBossServerConstants.JNDI_PORT_DETECT,
- IJBossServerConstants.JNDI_PORT_DETECT_XPATH,
IJBossServerConstants.JNDI_PORT_DEFAULT_XPATH,
- jndiText, jndiDetect, jndiDetectCombo, jndiListener);
- }
- }
-
- public class ChangeWebCommand extends SetPortCommand {
- public ChangeWebCommand(IServerWorkingCopy server) {
- super(server, Messages.EditorChangeWebCommandName,
- IJBossServerConstants.WEB_PORT, IJBossServerConstants.WEB_PORT_DETECT,
- IJBossServerConstants.WEB_PORT_DETECT_XPATH,
IJBossServerConstants.WEB_PORT_DEFAULT_XPATH,
- webText, webDetect, webDetectCombo, webListener);
- }
- }
-
-
- public class SetPortCommand extends ServerCommand {
+ public static class SetPortCommand extends ServerCommand {
+ ServerAttributeHelper helper;
String textAttribute, overrideAttribute, overridePathAttribute;
String preText, prePath, defaultPath;
boolean preOverride;
Text text;
Button button;
- Combo combo;
Listener listener;
- public SetPortCommand(IServerWorkingCopy server, String name,
+ String xpath;
+ public SetPortCommand(IServerWorkingCopy server, ServerAttributeHelper helper, String
name,
String textAttribute, String overrideAttribute, String overridePathAttribute,
- String pathDefault, Text text, Button button, Combo xpath, Listener listener) {
+ String pathDefault, Text text, Button button, String xpath, Listener listener) {
super(server, name);
+ this.helper = helper;
this.textAttribute = textAttribute;
this.overrideAttribute = overrideAttribute;
this.overridePathAttribute = overridePathAttribute;
this.defaultPath = pathDefault;
this.text = text;
this.button = button;
- this.combo = xpath;
this.listener = listener;
+ this.xpath = xpath;
}
public void execute() {
preText = helper.getAttribute(textAttribute, (String)null);
+ if( preText == null )
+ preText = findPort(new Path(defaultPath));
prePath = helper.getAttribute(overridePathAttribute, (String)defaultPath);
- preOverride = helper.getAttribute(overrideAttribute, false);
+ preOverride = helper.getAttribute(overrideAttribute, true);
helper.setAttribute(textAttribute, text.getText());
helper.setAttribute(overrideAttribute, button.getSelection());
- helper.setAttribute(overridePathAttribute, combo.getText());
+ helper.setAttribute(overridePathAttribute, xpath);
text.setEnabled(!button.getSelection());
text.setEditable(!button.getSelection());
- combo.setEnabled(button.getSelection());
if( button.getSelection() ) {
text.removeListener(SWT.Modify, listener);
- text.setText(findPort(new Path(combo.getText())));
+ text.setText(findPort(new Path(xpath)));
text.addListener(SWT.Modify, listener);
}
}
@@ -301,26 +356,27 @@
helper.setAttribute(overridePathAttribute, prePath);
// update ui
- combo.removeListener(SWT.Modify, listener);
text.removeListener(SWT.Modify, listener);
button.removeListener(SWT.Selection, listener);
button.setSelection(preOverride);
text.setText(preText == null ? "" : preText);
- int ind = combo.indexOf(prePath);
- if( ind == -1 )
- combo.clearSelection();
- else
- combo.select(ind);
-
text.setEnabled(!preOverride);
text.setEditable(!preOverride);
- combo.setEnabled(preOverride);
-
- combo.addListener(SWT.Modify, listener);
button.addListener(SWT.Selection, listener);
text.addListener(SWT.Modify, listener);
}
+
+ protected String findPort(IPath path) {
+ XPathQuery query = XPathModel.getDefault().getQuery(helper.getServer(), path);
+ if(query!=null) {
+ String result = query.getFirstResult();
+ if( result != null ) {
+ return result;
+ }
+ }
+ return "-1";
+ }
}
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-09-02 18:45:08 UTC (rev
10037)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2008-09-02 20:53:46 UTC (rev
10038)
@@ -4,6 +4,7 @@
<extension-point id="ServerViewExtension"
name="org.jboss.ide.eclipse.as.ui.serverViewExtension"
schema="schema/ServerViewExtension.exsd"/>
<extension-point id="EventLogLabelProvider"
name="org.jboss.ide.as.ui.eventLogLabelProvider"
schema="schema/EventLogLabelProvider.exsd"/>
<extension-point id="EventLogMajorType"
name="org.jboss.ide.eclipse.as.ui.eventLogMajorType"
schema="schema/EventLogMajorType.exsd"/>
+ <extension-point id="ServerEditorPortSection"
name="org.jboss.ide.as.ui.editor.portSection"
schema="schema/ServerEditorPortSection.exsd"/>
<extension
point="org.eclipse.wst.server.ui.serverImages">
@@ -339,6 +340,15 @@
</action>
</actionSet>
</extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.ui.ServerEditorPortSection">
+ <section
+
class="org.jboss.ide.eclipse.as.ui.editor.PortSection$JNDIPortEditorExtension">
+ </section>
+ <section
+
class="org.jboss.ide.eclipse.as.ui.editor.PortSection$WebPortEditorExtension">
+ </section>
+ </extension>
</plugin>
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/ServerEditorPortSection.exsd
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/ServerEditorPortSection.exsd
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/ServerEditorPortSection.exsd 2008-09-02
20:53:46 UTC (rev 10038)
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.ide.eclipse.as.ui"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.jboss.ide.eclipse.as.ui"
id="ServerEditorPortSection"
name="org.jboss.ide.as.ui.editor.portSection"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <element ref="section"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="section">
+ <complexType>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.ide.eclipse.as.ui.editor.PortSection$IPortEditorExtension"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>