diff options
14 files changed, 1030 insertions, 764 deletions
diff --git a/features/org.eclipse.emf.cdo-feature/feature.xml b/features/org.eclipse.emf.cdo-feature/feature.xml index 1873c0b870..4436b0edd7 100644 --- a/features/org.eclipse.emf.cdo-feature/feature.xml +++ b/features/org.eclipse.emf.cdo-feature/feature.xml @@ -161,4 +161,11 @@ version="0.0.0" unpack="false"/> + <plugin + id="org.eclipse.emf.cdo.ui.admin" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature> diff --git a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java index 3524098e9a..2b86180eea 100644 --- a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java +++ b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java @@ -54,7 +54,19 @@ public class CDOAdminView extends ContainerView "Open a new Net4j connector", org.eclipse.net4j.ui.shared.SharedIcons .getDescriptor(org.eclipse.net4j.ui.shared.SharedIcons.ETOOL_ADD_CONNECTOR), ConnectorFactory.PRODUCT_GROUP, - getContainer()); + getContainer(), "tcp") + { + @Override + public String getDefaultDescription(String factoryType) + { + if ("tcp".equals(factoryType)) + { + return "localhost"; + } + + return null; + } + }; private IListener containerListener = new ContainerEventAdapter<Object>() { diff --git a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF index 612e7831e8..9ebb194f4f 100644 --- a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF @@ -12,7 +12,11 @@ Bundle-ClassPath: . Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional, org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport Import-Package: org.osgi.framework;version="[1.3.0,2.0.0)";resolution:=optional -Export-Package: org.eclipse.net4j.internal.tcp;version="4.0.100";x-friends:="org.eclipse.net4j.tests,org.eclipse.net4j.defs,org.eclipse.emf.cdo.examples", +Export-Package: org.eclipse.net4j.internal.tcp;version="4.0.100"; + x-friends:="org.eclipse.net4j.tests, + org.eclipse.net4j.defs, + org.eclipse.emf.cdo.examples, + org.eclipse.net4j.ui", org.eclipse.net4j.internal.tcp.bundle;version="4.0.100";x-internal:=true, org.eclipse.net4j.internal.tcp.messages;version="4.0.100";x-internal:=true, org.eclipse.net4j.internal.tcp.ssl;version="4.0.100";x-friends:="org.eclipse.net4j.tests,org.eclipse.net4j.defs,org.eclipse.emf.cdo.examples", diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java index 5597190a3d..4d67e9f778 100644 --- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java +++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java @@ -1,82 +1,120 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Caspar De Groot - maintenance
- */
-package org.eclipse.net4j.internal.tcp;
-
-import org.eclipse.net4j.tcp.ITCPAcceptor;
-import org.eclipse.net4j.util.StringUtil;
-
-import org.eclipse.spi.net4j.AcceptorFactory;
-
-/**
- * @author Eike Stepper
- */
-public class TCPAcceptorFactory extends AcceptorFactory
-{
- public static final String TYPE = "tcp"; //$NON-NLS-1$
-
- private static final String SEPARATOR = ":"; //$NON-NLS-1$
-
- public TCPAcceptorFactory()
- {
- super(TYPE);
- }
-
- /**
- * Allows derived classes to override the TYPE identifier
- */
- protected TCPAcceptorFactory(String type)
- {
- super(type);
- }
-
- public TCPAcceptor create(String description)
- {
- String address = ITCPAcceptor.DEFAULT_ADDRESS;
- int port = ITCPAcceptor.DEFAULT_PORT;
-
- if (!StringUtil.isEmpty(description))
- {
- String[] tokens = description.split(SEPARATOR);
- if (!StringUtil.isEmpty(tokens[0]))
- {
- address = tokens[0];
- }
-
- if (tokens.length > 1 && !StringUtil.isEmpty(tokens[1]))
- {
- port = Integer.parseInt(tokens[1]);
- }
- }
-
- TCPAcceptor acceptor = createAcceptor();
- acceptor.setAddress(address);
- acceptor.setPort(port);
- return acceptor;
- }
-
- protected TCPAcceptor createAcceptor()
- {
- return new TCPAcceptor();
- }
-
- @Override
- public String getDescriptionFor(Object object)
- {
- if (object instanceof TCPAcceptor)
- {
- TCPAcceptor acceptor = (TCPAcceptor)object;
- return acceptor.getAddress() + SEPARATOR + acceptor.getPort();
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + * Caspar De Groot - maintenance + */ +package org.eclipse.net4j.internal.tcp; + +import org.eclipse.net4j.tcp.ITCPAcceptor; +import org.eclipse.net4j.util.StringUtil; + +import org.eclipse.spi.net4j.AcceptorFactory; + +/** + * @author Eike Stepper + */ +public class TCPAcceptorFactory extends AcceptorFactory +{ + public static final String TYPE = "tcp"; //$NON-NLS-1$ + + private static final String SEPARATOR = ":"; //$NON-NLS-1$ + + public TCPAcceptorFactory() + { + super(TYPE); + } + + /** + * Allows derived classes to override the TYPE identifier + */ + protected TCPAcceptorFactory(String type) + { + super(type); + } + + public TCPAcceptor create(String description) + { + Data data = new Data(description); + + TCPAcceptor acceptor = createAcceptor(); + acceptor.setAddress(data.getAddress()); + acceptor.setPort(data.getPort()); + return acceptor; + } + + protected TCPAcceptor createAcceptor() + { + return new TCPAcceptor(); + } + + @Override + public String getDescriptionFor(Object object) + { + if (object instanceof TCPAcceptor) + { + TCPAcceptor acceptor = (TCPAcceptor)object; + return acceptor.getAddress() + SEPARATOR + acceptor.getPort(); + } + + return null; + } + + /** + * @author Eike Stepper + */ + public static class Data + { + private String address = ITCPAcceptor.DEFAULT_ADDRESS; + + private int port = ITCPAcceptor.DEFAULT_PORT; + + public Data() + { + } + + public Data(String address, int port) + { + this.address = address; + this.port = port; + } + + public Data(String description) + { + if (!StringUtil.isEmpty(description)) + { + String[] tokens = description.split(SEPARATOR); + if (!StringUtil.isEmpty(tokens[0])) + { + address = tokens[0]; + } + + if (tokens.length > 1 && !StringUtil.isEmpty(tokens[1])) + { + port = Integer.parseInt(tokens[1]); + } + } + } + + public String getAddress() + { + return address == null ? "" : address; + } + + public int getPort() + { + return port; + } + + @Override + public String toString() + { + return address + SEPARATOR + port; + } + } +} diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java index f7281a5dae..3982bedbdd 100644 --- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java +++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java @@ -1,101 +1,99 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Caspar De Groot - maintenance
- */
-package org.eclipse.net4j.internal.tcp;
-
-import org.eclipse.net4j.tcp.ITCPConnector;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import org.eclipse.spi.net4j.ConnectorFactory;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-/**
- * @author Eike Stepper
- */
-public class TCPConnectorFactory extends ConnectorFactory
-{
- public static final String TYPE = "tcp"; //$NON-NLS-1$
-
- private static final String URL_SCHEME = "http://"; //$NON-NLS-1$
-
- public TCPConnectorFactory()
- {
- super(TYPE);
- }
-
- /**
- * Allows derived classes to override the TYPE identifier
- */
- protected TCPConnectorFactory(String type)
- {
- super(type);
- }
-
- public TCPConnector create(String description)
- {
- try
- {
- // TODO Don't use URL
- // Scheme "tcp://" would be rejected!
- URL url = new URL(URL_SCHEME + description);
- String userID = url.getUserInfo();
- String host = url.getHost();
- int port = url.getPort();
- if (port == -1)
- {
- port = ITCPConnector.DEFAULT_PORT;
- }
-
- TCPConnector connector = createConnector();
- connector.setUserID(userID);
- connector.setHost(host);
- connector.setPort(port);
- return connector;
- }
- catch (MalformedURLException ex)
- {
- throw new ProductCreationException(ex);
- }
- }
-
- protected TCPConnector createConnector()
- {
- return new TCPClientConnector();
- }
-
- @Override
- public String getDescriptionFor(Object object)
- {
- if (object instanceof TCPConnector)
- {
- TCPConnector connector = (TCPConnector)object;
- String description = connector.getHost();
- String userID = connector.getUserID();
- if (!StringUtil.isEmpty(userID))
- {
- description = userID + "@" + description; //$NON-NLS-1$
- }
-
- int port = connector.getPort();
- if (port != ITCPConnector.DEFAULT_PORT)
- {
- description = description + ":" + port; //$NON-NLS-1$
- }
-
- return description;
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + * Caspar De Groot - maintenance + */ +package org.eclipse.net4j.internal.tcp; + +import org.eclipse.net4j.tcp.ITCPConnector; +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.factory.ProductCreationException; + +import org.eclipse.spi.net4j.ConnectorFactory; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * @author Eike Stepper + */ +public class TCPConnectorFactory extends ConnectorFactory +{ + public static final String TYPE = "tcp"; //$NON-NLS-1$ + + public TCPConnectorFactory() + { + super(TYPE); + } + + /** + * Allows derived classes to override the TYPE identifier + */ + protected TCPConnectorFactory(String type) + { + super(type); + } + + public TCPConnector create(String description) + { + try + { + // TODO Don't use URL + // Scheme "tcp://" would be rejected! + URL url = new URL("http://" + description); + String userID = url.getUserInfo(); + String host = url.getHost(); + int port = url.getPort(); + if (port == -1) + { + port = ITCPConnector.DEFAULT_PORT; + } + + TCPConnector connector = createConnector(); + connector.setUserID(userID); + connector.setHost(host); + connector.setPort(port); + return connector; + } + catch (MalformedURLException ex) + { + throw new ProductCreationException(ex); + } + } + + protected TCPConnector createConnector() + { + return new TCPClientConnector(); + } + + @Override + public String getDescriptionFor(Object object) + { + if (object instanceof TCPConnector) + { + TCPConnector connector = (TCPConnector)object; + String description = connector.getHost(); + String userID = connector.getUserID(); + if (!StringUtil.isEmpty(userID)) + { + description = userID + "@" + description; //$NON-NLS-1$ + } + + int port = connector.getPort(); + if (port != ITCPConnector.DEFAULT_PORT) + { + description = description + ":" + port; //$NON-NLS-1$ + } + + return description; + } + + return null; + } +} diff --git a/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF index 95173ed565..4b069b2d7a 100644 --- a/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport, org.eclipse.net4j.util.ui;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.net4j.ui.shared;bundle-version="[4.0.0,5.0.0)", - org.eclipse.net4j.jvm;bundle-version="[4.1.0,5.0.0)";resolution:=optional + org.eclipse.net4j.jvm;bundle-version="[4.0.0,5.0.0)";resolution:=optional, + org.eclipse.net4j.tcp;bundle-version="[4.0.0,5.0.0)";resolution:=optional Export-Package: org.eclipse.net4j.ui;version="4.1.0", org.eclipse.net4j.internal.ui.bundle;version="4.1.0";x-internal:=true, org.eclipse.net4j.internal.ui.container;version="4.1.0";x-internal:=true, diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java index 9df1eb541e..beae7000bc 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java @@ -1,73 +1,79 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.net4j.internal.ui.container;
-
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.ui.container.ElementWizard;
-import org.eclipse.net4j.util.ui.container.ElementWizardFactory;
-
-import org.eclipse.spi.net4j.ConnectorFactory;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * @author Eike Stepper
- * @author Martin Fluegge
- * @since 4.0
- */
-public class JVMConnectorWizard extends ElementWizard implements ModifyListener
-{
- private Text acceptorNameText;
-
- public JVMConnectorWizard()
- {
- }
-
- @Override
- protected void create(Composite parent)
- {
- acceptorNameText = addText(parent, "Acceptor Name:");
- acceptorNameText.addModifyListener(this);
- }
-
- public void modifyText(ModifyEvent e)
- {
- String acceptorName = acceptorNameText.getText();
- if (acceptorName.length() == 0)
- {
- setValidationError(acceptorNameText, "Acceptor name is empty.");
- return;
- }
-
- setResultDescription(acceptorName);
- setValidationError(acceptorNameText, null);
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends ElementWizardFactory
- {
- public Factory()
- {
- super(ConnectorFactory.PRODUCT_GROUP, "jvm");
- }
-
- @Override
- public JVMConnectorWizard create(String description) throws ProductCreationException
- {
- return new JVMConnectorWizard();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.net4j.internal.ui.container; + +import org.eclipse.net4j.util.factory.ProductCreationException; +import org.eclipse.net4j.util.ui.container.ElementWizard; +import org.eclipse.net4j.util.ui.container.ElementWizardFactory; + +import org.eclipse.spi.net4j.ConnectorFactory; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +/** + * @author Eike Stepper + * @author Martin Fluegge + * @since 4.0 + */ +public class JVMConnectorWizard extends ElementWizard implements ModifyListener +{ + private Text acceptorNameText; + + public JVMConnectorWizard() + { + } + + @Override + protected void create(Composite parent) + { + acceptorNameText = addText(parent, "Acceptor Name:"); + acceptorNameText.addModifyListener(this); + + String description = getDefaultDescription(); + if (description != null) + { + acceptorNameText.setText(description); + } + } + + public void modifyText(ModifyEvent e) + { + String acceptorName = acceptorNameText.getText(); + if (acceptorName.length() == 0) + { + setValidationError(acceptorNameText, "Acceptor name is empty."); + return; + } + + setResultDescription(acceptorName); + setValidationError(acceptorNameText, null); + } + + /** + * @author Eike Stepper + */ + public static class Factory extends ElementWizardFactory + { + public Factory() + { + super(ConnectorFactory.PRODUCT_GROUP, "jvm"); + } + + @Override + public JVMConnectorWizard create(String description) throws ProductCreationException + { + return new JVMConnectorWizard(); + } + } +} diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPAcceptorWizard.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPAcceptorWizard.java index 95393b79b5..2188e1eda8 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPAcceptorWizard.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPAcceptorWizard.java @@ -11,6 +11,8 @@ */ package org.eclipse.net4j.internal.ui.container; +import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory; +import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory.Data; import org.eclipse.net4j.util.factory.ProductCreationException; import org.eclipse.net4j.util.ui.container.ElementWizard; import org.eclipse.net4j.util.ui.container.ElementWizardFactory; @@ -44,6 +46,14 @@ public class TCPAcceptorWizard extends ElementWizard implements ModifyListener portText = addText(parent, "Port:"); portText.addModifyListener(this); + + String description = getDefaultDescription(); + if (description != null) + { + Data data = new TCPAcceptorFactory.Data(description); + addressText.setText(data.getAddress()); + portText.setText(Integer.toString(data.getPort())); + } } public void modifyText(ModifyEvent e) diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPConnectorWizard.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPConnectorWizard.java index 8c8209a954..ba7ebe7894 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPConnectorWizard.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/TCPConnectorWizard.java @@ -1,84 +1,110 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.net4j.internal.ui.container;
-
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.ui.container.ElementWizard;
-import org.eclipse.net4j.util.ui.container.ElementWizardFactory;
-
-import org.eclipse.spi.net4j.ConnectorFactory;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * @author Eike Stepper
- * @author Martin Fluegge
- * @since 4.0
- */
-public class TCPConnectorWizard extends ElementWizard implements ModifyListener
-{
- private Text hostText;
-
- private Text portText;
-
- public TCPConnectorWizard()
- {
- }
-
- @Override
- protected void create(Composite parent)
- {
- hostText = addText(parent, "Host:");
- hostText.addModifyListener(this);
-
- portText = addText(parent, "Port:");
- portText.addModifyListener(this);
- }
-
- public void modifyText(ModifyEvent e)
- {
- String host = hostText.getText();
- if (host.length() == 0)
- {
- setValidationError(hostText, "Host name is empty.");
- return;
- }
-
- String port = portText.getText();
- if (port.length() != 0)
- {
- host += ":" + port;
- }
-
- setResultDescription(host);
- setValidationError(hostText, null);
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends ElementWizardFactory
- {
- public Factory()
- {
- super(ConnectorFactory.PRODUCT_GROUP, "tcp");
- }
-
- @Override
- public TCPConnectorWizard create(String description) throws ProductCreationException
- {
- return new TCPConnectorWizard();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.net4j.internal.ui.container; + +import org.eclipse.net4j.internal.ui.bundle.OM; +import org.eclipse.net4j.util.factory.ProductCreationException; +import org.eclipse.net4j.util.ui.container.ElementWizard; +import org.eclipse.net4j.util.ui.container.ElementWizardFactory; + +import org.eclipse.spi.net4j.ConnectorFactory; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * @author Eike Stepper + * @author Martin Fluegge + * @since 4.0 + */ +public class TCPConnectorWizard extends ElementWizard implements ModifyListener +{ + private Text hostText; + + private Text portText; + + public TCPConnectorWizard() + { + } + + @Override + protected void create(Composite parent) + { + hostText = addText(parent, "Host:"); + hostText.addModifyListener(this); + + portText = addText(parent, "Port:"); + portText.addModifyListener(this); + + String description = getDefaultDescription(); + if (description != null) + { + try + { + // TODO Don't use URL + // Scheme "tcp://" would be rejected! + URL url = new URL("http://" + description); + // String userID = url.getUserInfo(); + hostText.setText(url.getHost()); + int port = url.getPort(); + if (port != -1) + { + portText.setText(Integer.toString(port)); + } + } + catch (MalformedURLException ex) + { + OM.LOG.error(ex); + } + } + } + + public void modifyText(ModifyEvent e) + { + String host = hostText.getText(); + if (host.length() == 0) + { + setValidationError(hostText, "Host name is empty."); + return; + } + + String port = portText.getText(); + if (port.length() != 0) + { + host += ":" + port; + } + + setResultDescription(host); + setValidationError(hostText, null); + } + + /** + * @author Eike Stepper + */ + public static class Factory extends ElementWizardFactory + { + public Factory() + { + super(ConnectorFactory.PRODUCT_GROUP, "tcp"); + } + + @Override + public TCPConnectorWizard create(String description) throws ProductCreationException + { + return new TCPConnectorWizard(); + } + } +} diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java index d4593002a8..5791387f7b 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java @@ -33,7 +33,19 @@ public class AcceptorsView extends ContainerView public final static String ID = "org.eclipse.net4j.AcceptorsView"; //$NON-NLS-1$ private IAction newAcceptorAction = new ElementWizardAction(getShell(), "New Acceptor", "Open a new Net4j acceptor", - SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_ACCEPTOR), AcceptorFactory.PRODUCT_GROUP, getContainer()); + SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_ACCEPTOR), AcceptorFactory.PRODUCT_GROUP, getContainer(), "tcp") + { + @Override + public String getDefaultDescription(String factoryType) + { + if ("tcp".equals(factoryType)) + { + return "0.0.0.0:2036"; + } + + return null; + } + }; // private Action addAcceptorAction2036 = new SafeAction(Messages.getString("AcceptorsView_0"), //$NON-NLS-1$ // Messages.getString("AcceptorsView_1"), //$NON-NLS-1$ diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java index dd6c17607f..67f5bd90b0 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java @@ -34,7 +34,19 @@ public class ConnectorsView extends ContainerView private IAction newConnectorAction = new ElementWizardAction(getShell(), "New Connector", "Open a new Net4j connector", SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_CONNECTOR), - ConnectorFactory.PRODUCT_GROUP, getContainer()); + ConnectorFactory.PRODUCT_GROUP, getContainer(), "tcp") + { + @Override + public String getDefaultDescription(String factoryType) + { + if ("tcp".equals(factoryType)) + { + return "localhost"; + } + + return null; + } + }; public ConnectorsView() { diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardAction.java index fbeee6ffb4..a6c5f0160b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardAction.java @@ -20,39 +20,70 @@ public class ElementWizardAction extends LongRunningAction private String title; + private String toolTip; + private String productGroup; private String factoryType; private String description; + private String defaultFactoryType; + private IManagedContainer container; + public ElementWizardAction(Shell shell, String title, String toolTip, ImageDescriptor image, String productGroup) + { + this(shell, title, toolTip, image, productGroup, IPluginContainer.INSTANCE); + } + public ElementWizardAction(Shell shell, String title, String toolTip, ImageDescriptor image, String productGroup, IManagedContainer container) { + this(shell, title, toolTip, image, productGroup, container, null); + } + + public ElementWizardAction(Shell shell, String title, String toolTip, ImageDescriptor image, String productGroup, + IManagedContainer container, String defaultFactoryType) + { super(title, toolTip, image); this.shell = shell; this.title = title; + this.toolTip = toolTip; this.productGroup = productGroup; this.container = container; + this.defaultFactoryType = defaultFactoryType; } - public ElementWizardAction(Shell shell, String title, String toolTip, ImageDescriptor image, String productGroup) + public String getDefaultFactoryType() { - this(shell, title, toolTip, image, productGroup, IPluginContainer.INSTANCE); + return defaultFactoryType; + } + + /** + * Can be overridden by subclasses. + */ + public String getDefaultDescription(String factoryType) + { + return null; } @Override protected void preRun() throws Exception { - ElementWizardDialog dialog = new ElementWizardDialog(shell, title, productGroup) + ElementWizardDialog dialog = new ElementWizardDialog(shell, title, toolTip, productGroup, defaultFactoryType) { @Override protected IManagedContainer getContainer() { return container; } + + @Override + protected String getDefaultDescription(String factoryType) + { + return ElementWizardAction.this.getDefaultDescription(factoryType); + } }; if (dialog.open() == ElementWizardDialog.OK) diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java index 36bf114f58..70933d3b2f 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java @@ -1,413 +1,478 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.ui.container;
-
-import org.eclipse.net4j.util.container.FactoryNotFoundException;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.event.INotifier;
-import org.eclipse.net4j.util.event.Notifier;
-import org.eclipse.net4j.util.ui.UIUtil;
-import org.eclipse.net4j.util.ui.ValidationContext;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.FillLayout;
-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.Control;
-import org.eclipse.swt.widgets.Label;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- * @since 3.1
- */
-public abstract class ElementWizardComposite extends Composite implements IListener
-{
- private static final IElementWizard NO_WIZARD = new ElementWizard()
- {
- @Override
- protected void create(Composite parent)
- {
- // Do nothing
- }
- };
-
- private String productGroup;
-
- private String label;
-
- private List<String> factoryTypes;
-
- private Map<String, String> defaultDescriptions = new HashMap<String, String>();
-
- private List<IElementWizard> wizards;
-
- private Map<IElementWizard, List<Control>> wizardControls = new HashMap<IElementWizard, List<Control>>();
-
- private Map<Control, IElementWizard> controlWizards = new HashMap<Control, IElementWizard>();
-
- private ValidationContext validationContext;
-
- private boolean firstLayout = true;
-
- private Notifier notifier = new Notifier();
-
- public ElementWizardComposite(Composite parent, int style, String productGroup, String label)
- {
- this(parent, style, productGroup, label, null);
- }
-
- /**
- * @since 3.2
- */
- public ElementWizardComposite(Composite parent, int style, String productGroup, String label,
- ValidationContext validationContext)
- {
- super(parent, style);
- this.productGroup = productGroup;
- this.label = label;
-
- setValidationContext(validationContext);
- create();
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public String getLabel()
- {
- return label;
- }
-
- public void setValidationContext(ValidationContext validationContext)
- {
- this.validationContext = validationContext;
- }
-
- public String getDefaultDescription(String factoryType)
- {
- return defaultDescriptions.get(factoryType);
- }
-
- public void setDefaultDescription(String factoryType, String value)
- {
- defaultDescriptions.put(factoryType, value);
- }
-
- protected void init()
- {
- IManagedContainer container = getContainer();
- factoryTypes = new ArrayList<String>(container.getFactoryTypes(getProductGroup()));
- Collections.sort(factoryTypes);
-
- wizards = new ArrayList<IElementWizard>();
- wizardControls.put(NO_WIZARD, new ArrayList<Control>());
-
- for (Iterator<String> it = factoryTypes.iterator(); it.hasNext();)
- {
- String factoryType = it.next();
-
- try
- {
- String description = getDefaultDescription(factoryType);
-
- IElementWizard wizard = (IElementWizard)container.getElement(ElementWizardFactory.PRODUCT_GROUP,
- getProductGroup() + ":" + factoryType, description);
- wizards.add(wizard);
- wizardControls.put(wizard, new ArrayList<Control>());
-
- if (wizard instanceof ElementWizard)
- {
- ElementWizard impl = (ElementWizard)wizard;
- impl.addListener(this);
- }
- }
- catch (FactoryNotFoundException ex)
- {
- it.remove();
- }
- }
- }
-
- /**
- * @since 3.2
- */
- public void notifyEvent(IEvent event)
- {
- notifier.fireEvent(event);
- }
-
- protected List<String> getFactoryTypes()
- {
- return factoryTypes;
- }
-
- protected void create()
- {
- init();
- setLayout(new GridLayout(2, false));
-
- {
- Label label = new Label(this, SWT.NONE);
- label.setText(getLabel());
- label.setLayoutData(UIUtil.createGridData(false, false));
-
- createFactoryTypeControl();
- harvestControls(NO_WIZARD);
- }
-
- for (int i = 0; i < wizards.size(); i++)
- {
- String factoryType = factoryTypes.get(i);
- IElementWizard wizard = wizards.get(i);
- wizard.create(this, getContainer(), productGroup, factoryType, null, validationContext);
- harvestControls(wizard);
- }
-
- if (!factoryTypes.isEmpty())
- {
- setFactoryType(factoryTypes.get(0));
- }
- }
-
- protected void factoryTypeChanged()
- {
- String newFactoryType = getFactoryType();
- List<Control> controlsToRefresh = new ArrayList<Control>();
-
- for (int i = 0; i < wizards.size(); i++)
- {
- IElementWizard wizard = wizards.get(i);
-
- String factoryType = factoryTypes.get(i);
- boolean visible = factoryType.equals(newFactoryType);
-
- for (Control control : wizardControls.get(wizard))
- {
- control.setVisible(visible);
-
- if (!visible)
- {
- control.moveBelow(null);
- }
-
- controlsToRefresh.add(control);
- }
- }
-
- // layout(controlsToRefresh.toArray(new Control[controlsToRefresh.size()]));
- // layout(getChildren());
-
- layout();
- notifier.fireEvent();
- }
-
- @Override
- public void layout()
- {
- if (firstLayout)
- {
- super.layout();
- firstLayout = false;
- }
- else
- {
- super.layout(getChildren());
- }
- }
-
- protected void harvestControls(IElementWizard wizard)
- {
- for (Control child : getChildren())
- {
- if (!controlWizards.containsKey(child))
- {
- controlWizards.put(child, wizard);
- wizardControls.get(wizard).add(child);
- }
- }
- }
-
- protected IManagedContainer getContainer()
- {
- return IPluginContainer.INSTANCE;
- }
-
- /**
- * @since 3.2
- */
- public final INotifier getNotifier()
- {
- return notifier;
- }
-
- public String getDescription()
- {
- String resultType = getFactoryType();
- for (int i = 0; i < wizards.size(); i++)
- {
- String factoryType = factoryTypes.get(i);
- if (resultType.equals(factoryType))
- {
- return wizards.get(i).getResultDescription();
- }
- }
-
- return null;
- }
-
- public abstract String getFactoryType();
-
- protected abstract void setFactoryType(String factoryType);
-
- protected abstract void createFactoryTypeControl();
-
- /**
- * @author Eike Stepper
- */
- public static class WithCombo extends ElementWizardComposite implements SelectionListener
- {
- private Combo combo;
-
- public WithCombo(Composite parent, int style, String productGroup, String label)
- {
- super(parent, style, productGroup, label);
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- factoryTypeChanged();
- }
-
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- @Override
- public String getFactoryType()
- {
- return combo.getText();
- }
-
- @Override
- protected void setFactoryType(String factoryType)
- {
- int index = getFactoryTypes().indexOf(factoryType);
- if (index == -1)
- {
- combo.setText(factoryType);
- }
- else
- {
- combo.select(index);
- }
-
- factoryTypeChanged();
- }
-
- @Override
- protected void createFactoryTypeControl()
- {
- combo = new Combo(this, SWT.SINGLE);
- for (String factoryType : getFactoryTypes())
- {
- combo.add(factoryType);
- }
-
- combo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
- combo.addSelectionListener(this);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class WithRadios extends ElementWizardComposite implements SelectionListener
- {
- private Composite composite;
-
- public WithRadios(Composite parent, int style, String productGroup, String label)
- {
- super(parent, style, productGroup, label);
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- factoryTypeChanged();
- }
-
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- @Override
- public String getFactoryType()
- {
- Control[] choices = composite.getChildren();
-
- for (int i = 0; i < choices.length; i++)
- {
- Button choice = (Button)choices[i];
- if (choice.getSelection())
- {
- return getFactoryTypes().get(i);
- }
- }
-
- return null;
- }
-
- @Override
- protected void setFactoryType(String factoryType)
- {
- List<String> factoryTypes = getFactoryTypes();
- Control[] choices = composite.getChildren();
-
- for (int i = 0; i < factoryTypes.size(); i++)
- {
- Button choice = (Button)choices[i];
- choice.setSelection(factoryTypes.get(i).equals(factoryType));
- }
-
- factoryTypeChanged();
- }
-
- @Override
- protected void createFactoryTypeControl()
- {
- composite = new Composite(this, SWT.SINGLE);
- composite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
- composite.setLayout(new FillLayout());
- for (String factoryType : getFactoryTypes())
- {
- Button choice = new Button(composite, SWT.RADIO);
- choice.setText(factoryType);
- choice.addSelectionListener(this);
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.util.ui.container; + +import org.eclipse.net4j.util.container.FactoryNotFoundException; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.event.INotifier; +import org.eclipse.net4j.util.event.Notifier; +import org.eclipse.net4j.util.ui.UIUtil; +import org.eclipse.net4j.util.ui.ValidationContext; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +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.Control; +import org.eclipse.swt.widgets.Label; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * @author Eike Stepper + * @since 3.1 + */ +public abstract class ElementWizardComposite extends Composite implements IListener +{ + private static final IElementWizard NO_WIZARD = new ElementWizard() + { + @Override + protected void create(Composite parent) + { + // Do nothing + } + }; + + private String productGroup; + + private String label; + + private List<String> factoryTypes; + + private String defaultFactoryType; + + private List<IElementWizard> wizards; + + private Map<IElementWizard, List<Control>> wizardControls = new HashMap<IElementWizard, List<Control>>(); + + private Map<Control, IElementWizard> controlWizards = new HashMap<Control, IElementWizard>(); + + private ValidationContext validationContext; + + private boolean firstLayout = true; + + private Notifier notifier = new Notifier(); + + public ElementWizardComposite(Composite parent, int style, String productGroup, String label) + { + this(parent, style, productGroup, label, null); + } + + /** + * @since 3.2 + */ + public ElementWizardComposite(Composite parent, int style, String productGroup, String label, + ValidationContext validationContext) + { + this(parent, style, productGroup, label, validationContext, null); + } + + /** + * @since 3.2 + */ + public ElementWizardComposite(Composite parent, int style, String productGroup, String label, + ValidationContext validationContext, String defaultFactoryType) + { + super(parent, style); + this.productGroup = productGroup; + this.label = label; + this.defaultFactoryType = defaultFactoryType; + + setValidationContext(validationContext); + create(); + } + + public String getProductGroup() + { + return productGroup; + } + + public String getLabel() + { + return label; + } + + public void setValidationContext(ValidationContext validationContext) + { + this.validationContext = validationContext; + } + + /** + * @since 3.2 + */ + public String getDefaultFactoryType() + { + return defaultFactoryType; + } + + /** + * Can be overridden by subclasses. + */ + public String getDefaultDescription(String factoryType) + { + return null; + } + + /** + * @deprecated Override {@link #getDefaultDescription(String)} instead. + */ + @Deprecated + public void setDefaultDescription(String factoryType, String value) + { + // Do nothing + } + + protected void init() + { + IManagedContainer container = getContainer(); + factoryTypes = new ArrayList<String>(container.getFactoryTypes(getProductGroup())); + Collections.sort(factoryTypes); + + wizards = new ArrayList<IElementWizard>(); + wizardControls.put(NO_WIZARD, new ArrayList<Control>()); + + for (Iterator<String> it = factoryTypes.iterator(); it.hasNext();) + { + String factoryType = it.next(); + + try + { + IElementWizard wizard = (IElementWizard)container.getElement(ElementWizardFactory.PRODUCT_GROUP, + getProductGroup() + ":" + factoryType, null); + + wizards.add(wizard); + wizardControls.put(wizard, new ArrayList<Control>()); + + if (wizard instanceof ElementWizard) + { + ElementWizard impl = (ElementWizard)wizard; + impl.addListener(this); + } + } + catch (FactoryNotFoundException ex) + { + it.remove(); + } + } + } + + /** + * @since 3.2 + */ + public void notifyEvent(IEvent event) + { + notifier.fireEvent(event); + } + + protected List<String> getFactoryTypes() + { + return factoryTypes; + } + + protected void create() + { + init(); + setLayout(new GridLayout(2, false)); + + { + Label label = new Label(this, SWT.NONE); + label.setText(getLabel()); + label.setLayoutData(UIUtil.createGridData(false, false)); + + createFactoryTypeControl(); + harvestControls(NO_WIZARD); + } + + for (int i = 0; i < wizards.size(); i++) + { + String factoryType = factoryTypes.get(i); + String defaultDescription = getDefaultDescription(factoryType); + + IElementWizard wizard = wizards.get(i); + wizard.create(this, getContainer(), productGroup, factoryType, defaultDescription, validationContext); + harvestControls(wizard); + } + + if (defaultFactoryType != null) + { + setFactoryType(defaultFactoryType); + } + else if (!factoryTypes.isEmpty()) + { + setFactoryType(factoryTypes.get(0)); + } + } + + protected void factoryTypeChanged() + { + String newFactoryType = getFactoryType(); + List<Control> controlsToRefresh = new ArrayList<Control>(); + + for (int i = 0; i < wizards.size(); i++) + { + IElementWizard wizard = wizards.get(i); + + String factoryType = factoryTypes.get(i); + boolean visible = factoryType.equals(newFactoryType); + + for (Control control : wizardControls.get(wizard)) + { + control.setVisible(visible); + + if (!visible) + { + control.moveBelow(null); + } + + controlsToRefresh.add(control); + } + } + + // layout(controlsToRefresh.toArray(new Control[controlsToRefresh.size()])); + // layout(getChildren()); + + layout(); + notifier.fireEvent(); + } + + @Override + public void layout() + { + if (firstLayout) + { + super.layout(); + firstLayout = false; + } + else + { + super.layout(getChildren()); + } + } + + protected void harvestControls(IElementWizard wizard) + { + for (Control child : getChildren()) + { + if (!controlWizards.containsKey(child)) + { + controlWizards.put(child, wizard); + wizardControls.get(wizard).add(child); + } + } + } + + protected IManagedContainer getContainer() + { + return IPluginContainer.INSTANCE; + } + + /** + * @since 3.2 + */ + public final INotifier getNotifier() + { + return notifier; + } + + public String getDescription() + { + String resultType = getFactoryType(); + for (int i = 0; i < wizards.size(); i++) + { + String factoryType = factoryTypes.get(i); + if (resultType.equals(factoryType)) + { + return wizards.get(i).getResultDescription(); + } + } + + return null; + } + + public abstract String getFactoryType(); + + protected abstract void setFactoryType(String factoryType); + + protected abstract void createFactoryTypeControl(); + + /** + * @author Eike Stepper + */ + public static class WithCombo extends ElementWizardComposite implements SelectionListener + { + private Combo combo; + + public WithCombo(Composite parent, int style, String productGroup, String label) + { + super(parent, style, productGroup, label); + } + + /** + * @since 3.2 + */ + public WithCombo(Composite parent, int style, String productGroup, String label, ValidationContext validationContext) + { + super(parent, style, productGroup, label, validationContext); + } + + /** + * @since 3.2 + */ + public WithCombo(Composite parent, int style, String productGroup, String label, + ValidationContext validationContext, String defaultFactoryType) + { + super(parent, style, productGroup, label, validationContext, defaultFactoryType); + } + + public void widgetSelected(SelectionEvent e) + { + factoryTypeChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e) + { + } + + @Override + public String getFactoryType() + { + return combo.getText(); + } + + @Override + protected void setFactoryType(String factoryType) + { + int index = getFactoryTypes().indexOf(factoryType); + if (index == -1) + { + combo.setText(factoryType); + } + else + { + combo.select(index); + } + + factoryTypeChanged(); + } + + @Override + protected void createFactoryTypeControl() + { + combo = new Combo(this, SWT.SINGLE); + for (String factoryType : getFactoryTypes()) + { + combo.add(factoryType); + } + + combo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); + combo.addSelectionListener(this); + } + } + + /** + * @author Eike Stepper + */ + public static class WithRadios extends ElementWizardComposite implements SelectionListener + { + private Composite composite; + + public WithRadios(Composite parent, int style, String productGroup, String label) + { + super(parent, style, productGroup, label); + } + + /** + * @since 3.2 + */ + public WithRadios(Composite parent, int style, String productGroup, String label, + ValidationContext validationContext) + { + super(parent, style, productGroup, label, validationContext); + } + + /** + * @since 3.2 + */ + public WithRadios(Composite parent, int style, String productGroup, String label, + ValidationContext validationContext, String defaultFactoryType) + { + super(parent, style, productGroup, label, validationContext, defaultFactoryType); + } + + public void widgetSelected(SelectionEvent e) + { + factoryTypeChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e) + { + } + + @Override + public String getFactoryType() + { + Control[] choices = composite.getChildren(); + + for (int i = 0; i < choices.length; i++) + { + Button choice = (Button)choices[i]; + if (choice.getSelection()) + { + return getFactoryTypes().get(i); + } + } + + return null; + } + + @Override + protected void setFactoryType(String factoryType) + { + List<String> factoryTypes = getFactoryTypes(); + Control[] choices = composite.getChildren(); + + for (int i = 0; i < factoryTypes.size(); i++) + { + Button choice = (Button)choices[i]; + choice.setSelection(factoryTypes.get(i).equals(factoryType)); + } + + factoryTypeChanged(); + } + + @Override + protected void createFactoryTypeControl() + { + composite = new Composite(this, SWT.SINGLE); + composite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); + composite.setLayout(new FillLayout()); + for (String factoryType : getFactoryTypes()) + { + Button choice = new Button(composite, SWT.RADIO); + choice.setText(factoryType); + choice.addSelectionListener(this); + } + } + } +} diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardDialog.java index 133b605794..36137b589e 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardDialog.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardDialog.java @@ -12,7 +12,9 @@ package org.eclipse.net4j.util.ui.container; import org.eclipse.net4j.util.container.IManagedContainer; import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.net4j.util.ui.ValidationContext; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -25,26 +27,43 @@ import org.eclipse.swt.widgets.Shell; * @author Eike Stepper * @since 3.2 */ -public class ElementWizardDialog extends TitleAreaDialog +public class ElementWizardDialog extends TitleAreaDialog implements ValidationContext { private String title; + private String toolTip; + private String productGroup; private String factoryType; private String description; + private String defaultFactoryType; + private ElementWizardComposite wizardComposite; - public ElementWizardDialog(Shell parentShell, String title, String productGroup) + public ElementWizardDialog(Shell parentShell, String title, String toolTip, String productGroup, + String defaultFactoryType) { super(parentShell); this.title = title; + this.toolTip = toolTip; this.productGroup = productGroup; + this.defaultFactoryType = defaultFactoryType; setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL | SWT.MAX | SWT.TITLE | SWT.RESIZE); } + public String getTitle() + { + return title; + } + + public String getToolTip() + { + return toolTip; + } + public String getProductGroup() { return productGroup; @@ -60,6 +79,11 @@ public class ElementWizardDialog extends TitleAreaDialog return description; } + public void setValidationError(Object source, String message) + { + setMessage(message, IMessageProvider.ERROR); + } + @Override protected void configureShell(Shell newShell) { @@ -71,12 +95,27 @@ public class ElementWizardDialog extends TitleAreaDialog protected Control createDialogArea(Composite parent) { setTitle(title); + if (toolTip != null) + { + setMessage(toolTip); + } + // setTitleImage(SharedIcons.getImage(SharedIcons.WIZBAN_PACKAGE_MANAGER)); Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout(1, false)); - wizardComposite = new ElementWizardComposite.WithRadios(composite, SWT.NONE, productGroup, "Type:"); + wizardComposite = new ElementWizardComposite.WithRadios(composite, SWT.NONE, productGroup, "Type:", this, + defaultFactoryType) + { + @Override + public String getDefaultDescription(String factoryType) + { + return ElementWizardDialog.this.getDefaultDescription(factoryType); + } + }; + wizardComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); return composite; @@ -87,6 +126,11 @@ public class ElementWizardDialog extends TitleAreaDialog return IPluginContainer.INSTANCE; } + protected String getDefaultDescription(String factoryType) + { + return null; + } + @Override protected void okPressed() { |