diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src')
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/handler/AddPeerCommandHandler.java | 107 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/help/IContextHelpIds.java | 4 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.java | 20 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.properties | 18 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewRemoteTargetWizard.java | 115 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/pages/NewRemoteTargetWizardPage.java (renamed from target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/dialogs/AddPeerDialog.java) | 516 |
6 files changed, 384 insertions, 396 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/handler/AddPeerCommandHandler.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/handler/AddPeerCommandHandler.java deleted file mode 100644 index de0f820d9..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/handler/AddPeerCommandHandler.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. 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: - * Uwe Stieber (Wind River) - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.tcf.ui.internal.handler; - -import java.util.Map; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.tm.tcf.protocol.IChannel; -import org.eclipse.tm.tcf.protocol.IPeer; -import org.eclipse.tm.tcf.protocol.Protocol; -import org.eclipse.tm.te.tcf.core.Tcf; -import org.eclipse.tm.te.tcf.core.interfaces.IChannelManager; -import org.eclipse.tm.te.tcf.locator.interfaces.nodes.ILocatorModel; -import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tm.te.tcf.locator.interfaces.services.ILocatorModelLookupService; -import org.eclipse.tm.te.tcf.ui.internal.dialogs.AddPeerDialog; -import org.eclipse.tm.te.tcf.ui.internal.model.Model; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.handlers.HandlerUtil; - - -/** - * Target Explorer: Adds a new peer to the TCF locator model. - */ -public class AddPeerCommandHandler extends AbstractHandler { - - /* (non-Javadoc) - * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - // Get the shell - Shell shell = HandlerUtil.getActiveShell(event); - // Open the dialog - AddPeerDialog dialog = new AddPeerDialog(shell); - if (dialog.open() == Window.OK) { - // Get the new peer attributes - final Map<String, String> peerAttributes = dialog.getPeerAttributes(); - if (peerAttributes != null) { - // Try to connect to the peer - IChannel channel = null; - try { - IWorkbenchPart activePart = HandlerUtil.getActivePart(event); - IEditorPart editorPart = activePart != null ? (IEditorPart)activePart.getAdapter(IEditorPart.class) : null; - final ISelectionProvider selectionProvider = editorPart != null ? editorPart.getEditorSite().getSelectionProvider() : null; - - Tcf.getChannelManager().openChannel(peerAttributes, new IChannelManager.DoneOpenChannel() { - public void doneOpenChannel(Throwable error, IChannel channel) { - if (error == null) { - IPeer peer = channel.getRemotePeer(); - if (selectionProvider != null && peer != null) { - // OK, we have the peer instance now, for the rest, - // we need the locator model - ILocatorModel model = Model.getModel(); - if (model != null) { - final IPeerModel peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peer.getID()); - if (peerNode != null) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - selectionProvider.setSelection(new StructuredSelection(peerNode)); - } - }); - } - } - } - } - - channel.close(); - } - }); - } catch (Exception e) { - } finally { - // Close the channel again - if (channel != null) { - final IChannel finChannel = channel; - if (Protocol.isDispatchThread()) { - finChannel.close(); - } else { - Protocol.invokeAndWait(new Runnable() { - public void run() { - finChannel.close(); - } - }); - } - } - } - } - } - - return null; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/help/IContextHelpIds.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/help/IContextHelpIds.java index 6497cb459..cdd7b9a48 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/help/IContextHelpIds.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/help/IContextHelpIds.java @@ -22,9 +22,9 @@ public interface IContextHelpIds { public final static String PREFIX = UIPlugin.getUniqueIdentifier() + "."; //$NON-NLS-1$ /** - * Add new peer dialog. + * New TCF remote target wizard main page. */ - public final static String ADD_PEER_DIALOG = PREFIX + "AddPeerDialog"; //$NON-NLS-1$ + public final static String NEW_REMOTE_TARGET_WIZARD_PAGE = PREFIX + "NewRemoteTargetWizardPage"; //$NON-NLS-1$ /** * Target Explorer details editor page: Node properties diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.java index e7267fb35..f0dadb93f 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.java @@ -83,15 +83,13 @@ public class Messages extends NLS { public static String NodePropertiesLabelProvider_services_local; public static String NodePropertiesLabelProvider_services_remote; - public static String AddPeerDialog_title; - - public static String TransportTypeControl_label; - - public static String AgentHostControl_label; - - public static String AgentPortControl_label; - - public static String PeerIdControl_label; - - public static String PeerNameControl_label; + public static String NewRemoteTargetWizard_windowTitle; + + public static String NewRemoteTargetWizardPage_title; + public static String NewRemoteTargetWizardPage_description; + public static String NewRemoteTargetWizardPage_TransportTypeControl_label; + public static String NewRemoteTargetWizardPage_AgentHostControl_label; + public static String NewRemoteTargetWizardPage_AgentPortControl_label; + public static String NewRemoteTargetWizardPage_PeerIdControl_label; + public static String NewRemoteTargetWizardPage_PeerNameControl_label; } diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.properties index 94fdbfa19..d656ee622 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/nls/Messages.properties @@ -19,12 +19,12 @@ NodePropertiesLabelProvider_services_remote=Remote Services AddPeerDialog_title=Add New Peer -TransportTypeControl_label=Type: - -AgentHostControl_label=Host: - -AgentPortControl_label=Port: - -PeerIdControl_label=ID: - -PeerNameControl_label=Name: +NewRemoteTargetWizard_windowTitle=New Remote Target + +NewRemoteTargetWizardPage_title=New Remote Target +NewRemoteTargetWizardPage_description=Specify the attributes to connect to the remote target. +NewRemoteTargetWizardPage_TransportTypeControl_label=Type: +NewRemoteTargetWizardPage_AgentHostControl_label=Host: +NewRemoteTargetWizardPage_AgentPortControl_label=Port: +NewRemoteTargetWizardPage_PeerIdControl_label=ID: +NewRemoteTargetWizardPage_PeerNameControl_label=Name: diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewRemoteTargetWizard.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewRemoteTargetWizard.java new file mode 100644 index 000000000..15a306277 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/NewRemoteTargetWizard.java @@ -0,0 +1,115 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Uwe Stieber (Wind River) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.te.tcf.ui.internal.wizards;
+
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.tm.tcf.protocol.IChannel;
+import org.eclipse.tm.tcf.protocol.IPeer;
+import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.te.tcf.core.Tcf;
+import org.eclipse.tm.te.tcf.core.interfaces.IChannelManager;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.ILocatorModel;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tm.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+import org.eclipse.tm.te.tcf.ui.internal.model.Model;
+import org.eclipse.tm.te.tcf.ui.internal.nls.Messages;
+import org.eclipse.tm.te.tcf.ui.internal.wizards.pages.NewRemoteTargetWizardPage;
+import org.eclipse.tm.te.ui.views.interfaces.IUIConstants;
+import org.eclipse.tm.te.ui.wizards.AbstractWizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * New TCF remote target wizard implementation.
+ */
+public class NewRemoteTargetWizard extends AbstractWizard implements INewWizard {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ // Set the window title
+ setWindowTitle(Messages.NewRemoteTargetWizard_windowTitle);
+ // Create and add the wizard pages
+ addPage(new NewRemoteTargetWizardPage());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ IWizardPage page = getPage(NewRemoteTargetWizardPage.class.getName());
+ if (page instanceof NewRemoteTargetWizardPage) {
+ // Trigger the saving of the widget history
+ ((NewRemoteTargetWizardPage)page).saveWidgetValues();
+ // Get the peer attributes map from the page
+ Map<String, String> peerAttributes = ((NewRemoteTargetWizardPage)page).getPeerAttributes();
+ if (peerAttributes != null) {
+ // Try to connect to the peer
+ IChannel channel = null;
+ try {
+ Tcf.getChannelManager().openChannel(peerAttributes, new IChannelManager.DoneOpenChannel() {
+ public void doneOpenChannel(Throwable error, IChannel channel) {
+ // We ignore the error here, because we don't present it to the user
+ if (channel != null && channel.getRemotePeer() != null) {
+ IPeer peer = channel.getRemotePeer();
+ ILocatorModel model = Model.getModel();
+ if (model != null) {
+ final IPeerModel peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(peer.getID());
+ if (peerNode != null && PlatformUI.isWorkbenchRunning()) {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
+ IViewReference reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference(IUIConstants.ID_EXPLORER);
+ IWorkbenchPart part = reference != null ? reference.getPart(false) : null;
+ ISelectionProvider selectionProvider = part != null && part.getSite() != null ? part.getSite().getSelectionProvider() : null;
+ if (selectionProvider != null) selectionProvider.setSelection(new StructuredSelection(peerNode));
+ }
+ }
+ });
+ }
+ }
+ }
+
+ if (channel != null) channel.close();
+ }
+ });
+ } catch (Exception e) {
+ } finally {
+ // Close the channel again
+ if (channel != null) {
+ final IChannel finChannel = channel;
+ if (Protocol.isDispatchThread()) {
+ finChannel.close();
+ } else {
+ Protocol.invokeAndWait(new Runnable() {
+ public void run() {
+ finChannel.close();
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/dialogs/AddPeerDialog.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/pages/NewRemoteTargetWizardPage.java index ab8446780..39f67d2b1 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/dialogs/AddPeerDialog.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/src/org/eclipse/tm/te/tcf/ui/internal/wizards/pages/NewRemoteTargetWizardPage.java @@ -1,267 +1,249 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. 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: - * Uwe Stieber (Wind River) - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.tcf.ui.internal.dialogs; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -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.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.tm.tcf.protocol.IPeer; -import org.eclipse.tm.te.tcf.ui.internal.help.IContextHelpIds; -import org.eclipse.tm.te.tcf.ui.internal.nls.Messages; -import org.eclipse.tm.te.ui.dialogs.CustomTrayDialog; - - -/** - * Target Explorer: Add peer dialog implementation. - */ -public class AddPeerDialog extends CustomTrayDialog { - private Combo fTransportTypeControl; - private Text fAddressControl; - private Text fPortControl; - private Text fPeerIdControl; - private Text fPeerNameControl; - - private Map<String, String> fPeerAttributes = null; - - /** - * Constructor. - * - * @param parent The parent shell used to view the dialog. - */ - public AddPeerDialog(Shell parent) { - this(parent, IContextHelpIds.ADD_PEER_DIALOG); - } - - /** - * Constructor. - * - * @param parent The parent shell used to view the dialog. - * @param contextHelpId The dialog context help id or <code>null</code>. - */ - public AddPeerDialog(Shell parent, String contextHelpId) { - super(parent, contextHelpId); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.ide.target.ui.dialogs.WRUnifiedTitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createDialogArea(Composite parent) { - Composite composite = (Composite)super.createDialogArea(parent); - - configureTitles(); - - Composite panel = new Composite(composite, SWT.NONE); - panel.setLayout(new GridLayout(2, false)); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - - // Add the controls - Label label = new Label(panel, SWT.NONE); - label.setText(Messages.TransportTypeControl_label); - - fTransportTypeControl = new Combo(panel, SWT.READ_ONLY); - fTransportTypeControl.setItems(new String[] { "TCP" }); //$NON-NLS-1$ - fTransportTypeControl.select(0); - fTransportTypeControl.setEnabled(false); - fTransportTypeControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - label = new Label(panel, SWT.NONE); - label.setText(Messages.AgentHostControl_label); - - fAddressControl = new Text(panel, SWT.SINGLE | SWT.BORDER); - fAddressControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fAddressControl.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updatePeerId(); - } - }); - - label = new Label(panel, SWT.NONE); - label.setText(Messages.AgentPortControl_label); - - fPortControl = new Text(panel, SWT.SINGLE | SWT.BORDER); - fPortControl.setText("1534"); //$NON-NLS-1$ - fPortControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fPortControl.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updatePeerId(); - } - }); - - label = new Label(panel, SWT.NONE); - label.setText(Messages.PeerIdControl_label); - - fPeerIdControl = new Text(panel, SWT.SINGLE | SWT.BORDER); - fPeerIdControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - label = new Label(panel, SWT.NONE); - label.setText(Messages.PeerNameControl_label); - - fPeerNameControl = new Text(panel, SWT.SINGLE | SWT.BORDER); - fPeerNameControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Setup the control content - setupContent(); - - // Adjust the font - applyDialogFont(composite); - - return composite; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createButtonBar(Composite parent) { - Control control = super.createButtonBar(parent); - validateDialog(); - return control; - } - - /** - * Configure the dialog title and the title area content. The method - * is called from {@link #createDialogArea(Composite)}. - */ - protected void configureTitles() { - setDialogTitle(Messages.AddPeerDialog_title); - } - - /** - * Setup the control content. - */ - protected void setupContent() { - restoreWidgetValues(); - updatePeerId(); - } - - /** - * Update peer id control. - */ - protected void updatePeerId() { - String address = fAddressControl.getText(); - String port = fPortControl.getText(); - String type = fTransportTypeControl.getText(); - - if (!"".equals(address) && !"".equals(port)) { //$NON-NLS-1$ //$NON-NLS-2$ - fPeerIdControl.setText(type + ":" //$NON-NLS-1$ - + address + ":" //$NON-NLS-1$ - + port); - } else { - fPeerIdControl.setText(""); //$NON-NLS-1$ - } - - validateDialog(); - } - - /** - * Validates the dialog. - */ - protected void validateDialog() { - boolean valid = true; - - if ("".equals(fAddressControl.getText()) || "".equals(fPortControl)) { //$NON-NLS-1$ //$NON-NLS-2$ - valid = false; - } - - if (getButton(IDialogConstants.OK_ID) != null) - getButton(IDialogConstants.OK_ID).setEnabled(valid); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() - */ - @Override - protected void cancelPressed() { - // Dispose the peer attributes - fPeerAttributes = null; - - super.cancelPressed(); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.ide.target.ui.dialogs.WRUnifiedTitleAreaDialog#okPressed() - */ - @Override - protected void okPressed() { - saveWidgetValues(); - - // Create a new peer attributes map - fPeerAttributes = new HashMap<String, String>(); - // Update with the current control content - updatePeerAttributes(fPeerAttributes); - - super.okPressed(); - } - - /** - * Updates the given attributes map with the current control content. - */ - protected void updatePeerAttributes(Map<String, String> peerAttributes) { - assert peerAttributes != null; - - peerAttributes.put(IPeer.ATTR_IP_HOST, fAddressControl.getText()); - peerAttributes.put(IPeer.ATTR_IP_PORT, fPortControl.getText()); - peerAttributes.put(IPeer.ATTR_ID, fPeerIdControl.getText()); - peerAttributes.put(IPeer.ATTR_NAME, fPeerNameControl.getText()); - peerAttributes.put(IPeer.ATTR_TRANSPORT_NAME, fTransportTypeControl.getText()); - } - - /** - * Returns the peer attributes. - * - * @return The peer attributes or <code>null</code> if canceled. - */ - public final Map<String, String> getPeerAttributes() { - return fPeerAttributes; - } - - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.ide.target.ui.dialogs.WRUnifiedTitleAreaDialog#saveWidgetValues() - */ - protected void saveWidgetValues() { - IDialogSettings settings = getDialogSettings(); - if (settings != null) { - // The transport type control is not saved - settings.put(IPeer.ATTR_IP_HOST, fAddressControl.getText()); - settings.put(IPeer.ATTR_IP_PORT, fPortControl.getText()); - settings.put(IPeer.ATTR_ID, fPeerIdControl.getText()); - settings.put(IPeer.ATTR_NAME, fPeerNameControl.getText()); - } - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.ide.target.ui.dialogs.WRUnifiedTitleAreaDialog#restoreWidgetValues() - */ - protected void restoreWidgetValues() { - IDialogSettings settings = getDialogSettings(); - if (settings != null) { - // The transport type control is not restored - if (settings.get(IPeer.ATTR_IP_HOST) != null) fAddressControl.setText(settings.get(IPeer.ATTR_IP_HOST)); - if (settings.get(IPeer.ATTR_IP_PORT) != null) fPortControl.setText(settings.get(IPeer.ATTR_IP_PORT)); - if (settings.get(IPeer.ATTR_ID) != null) fPeerIdControl.setText(settings.get(IPeer.ATTR_ID)); - if (settings.get(IPeer.ATTR_NAME) != null) fPeerNameControl.setText(settings.get(IPeer.ATTR_NAME)); - } - } -} +/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Uwe Stieber (Wind River) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.te.tcf.ui.internal.wizards.pages;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+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.swt.widgets.Text;
+import org.eclipse.tm.tcf.protocol.IPeer;
+import org.eclipse.tm.te.tcf.ui.internal.help.IContextHelpIds;
+import org.eclipse.tm.te.tcf.ui.internal.nls.Messages;
+import org.eclipse.tm.te.ui.wizards.pages.AbstractWizardPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Wizard page implementation querying all information needed
+ * to create the different TCF peer types.
+ */
+public class NewRemoteTargetWizardPage extends AbstractWizardPage {
+ private Combo fTransportTypeControl;
+ private Text fAddressControl;
+ private Text fPortControl;
+ private Text fPeerIdControl;
+ private Text fPeerNameControl;
+
+ /**
+ * Constructor.
+ */
+ public NewRemoteTargetWizardPage() {
+ this(NewRemoteTargetWizardPage.class.getName());
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param pageName The page name. Must not be <code>null</code>.
+ */
+ public NewRemoteTargetWizardPage(String pageName) {
+ super(pageName);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ // Setup title and description
+ setTitle(Messages.NewRemoteTargetWizardPage_title);
+ setDescription(Messages.NewRemoteTargetWizardPage_description);
+
+ // Create the main panel
+ Composite mainPanel = new Composite(parent, SWT.NONE);
+ mainPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ mainPanel.setLayout(new GridLayout());
+
+ setControl(mainPanel);
+
+ // Setup the help
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(mainPanel, IContextHelpIds.NEW_REMOTE_TARGET_WIZARD_PAGE);
+
+ // Create the main panel sub controls
+ createMainPanelControls(mainPanel);
+
+ // Adjust the font
+ Dialog.applyDialogFont(mainPanel);
+ }
+
+ /**
+ * Creates the main panel sub controls.
+ *
+ * @param parent The parent main panel composite. Must not be <code>null</code>.
+ */
+ protected void createMainPanelControls(Composite parent) {
+ Assert.isNotNull(parent);
+
+ Composite panel = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 0; layout.marginWidth = 0;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ // Add the controls
+ Label label = new Label(panel, SWT.NONE);
+ label.setText(Messages.NewRemoteTargetWizardPage_TransportTypeControl_label);
+
+ fTransportTypeControl = new Combo(panel, SWT.READ_ONLY);
+ fTransportTypeControl.setItems(new String[] { "TCP" }); //$NON-NLS-1$
+ fTransportTypeControl.select(0);
+ fTransportTypeControl.setEnabled(false);
+ fTransportTypeControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ label = new Label(panel, SWT.NONE);
+ label.setText(Messages.NewRemoteTargetWizardPage_AgentHostControl_label);
+
+ fAddressControl = new Text(panel, SWT.SINGLE | SWT.BORDER);
+ fAddressControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ fAddressControl.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updatePeerId();
+ }
+ });
+
+ label = new Label(panel, SWT.NONE);
+ label.setText(Messages.NewRemoteTargetWizardPage_AgentPortControl_label);
+
+ fPortControl = new Text(panel, SWT.SINGLE | SWT.BORDER);
+ fPortControl.setText("1534"); //$NON-NLS-1$
+ fPortControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ fPortControl.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updatePeerId();
+ }
+ });
+
+ label = new Label(panel, SWT.NONE);
+ label.setText(Messages.NewRemoteTargetWizardPage_PeerIdControl_label);
+
+ fPeerIdControl = new Text(panel, SWT.SINGLE | SWT.BORDER);
+ fPeerIdControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ label = new Label(panel, SWT.NONE);
+ label.setText(Messages.NewRemoteTargetWizardPage_PeerNameControl_label);
+
+ fPeerNameControl = new Text(panel, SWT.SINGLE | SWT.BORDER);
+ fPeerNameControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Restore the page history and trigger
+ // an update of the peer id
+ setupContent();
+ }
+
+ /**
+ * Setup the control content.
+ */
+ protected void setupContent() {
+ restoreWidgetValues();
+ updatePeerId();
+ }
+
+ /**
+ * Update peer id control.
+ */
+ protected void updatePeerId() {
+ String address = fAddressControl.getText();
+ String port = fPortControl.getText();
+ String type = fTransportTypeControl.getText();
+
+ if (!"".equals(address) && !"".equals(port)) { //$NON-NLS-1$ //$NON-NLS-2$
+ fPeerIdControl.setText(type + ":" //$NON-NLS-1$
+ + address + ":" //$NON-NLS-1$
+ + port);
+ } else {
+ fPeerIdControl.setText(""); //$NON-NLS-1$
+ }
+
+ validatePage();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.pages.AbstractWizardPage#validatePage()
+ */
+ @Override
+ public void validatePage() {
+ boolean valid = true;
+
+ if ("".equals(fAddressControl.getText()) || "".equals(fPortControl)) { //$NON-NLS-1$ //$NON-NLS-2$
+ valid = false;
+ }
+
+ setPageComplete(valid);
+ }
+
+ /**
+ * Updates the given attributes map with the current control content.
+ *
+ * @param peerAttributes The peer attributes map to update. Must not be <code>null</code>.
+ */
+ protected void updatePeerAttributes(Map<String, String> peerAttributes) {
+ Assert.isNotNull(peerAttributes);
+
+ peerAttributes.put(IPeer.ATTR_IP_HOST, fAddressControl.getText());
+ peerAttributes.put(IPeer.ATTR_IP_PORT, fPortControl.getText());
+ peerAttributes.put(IPeer.ATTR_ID, fPeerIdControl.getText());
+ peerAttributes.put(IPeer.ATTR_NAME, fPeerNameControl.getText());
+ peerAttributes.put(IPeer.ATTR_TRANSPORT_NAME, fTransportTypeControl.getText());
+ }
+
+ /**
+ * Returns the peer attributes.
+ *
+ * @return The peer attributes or <code>null</code> if canceled.
+ */
+ public final Map<String, String> getPeerAttributes() {
+ // Create a new peer attributes map
+ Map<String, String> peerAttributes = new HashMap<String, String>();
+ // Update with the current control content
+ updatePeerAttributes(peerAttributes);
+
+ return peerAttributes;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.pages.AbstractWizardPage#saveWidgetValues()
+ */
+ @Override
+ public void saveWidgetValues() {
+ IDialogSettings settings = getDialogSettings();
+ if (settings != null) {
+ // The transport type control is not saved
+ settings.put(IPeer.ATTR_IP_HOST, fAddressControl.getText());
+ settings.put(IPeer.ATTR_IP_PORT, fPortControl.getText());
+ settings.put(IPeer.ATTR_ID, fPeerIdControl.getText());
+ settings.put(IPeer.ATTR_NAME, fPeerNameControl.getText());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.pages.AbstractWizardPage#restoreWidgetValues()
+ */
+ @Override
+ public void restoreWidgetValues() {
+ IDialogSettings settings = getDialogSettings();
+ if (settings != null) {
+ // The transport type control is not restored
+ if (settings.get(IPeer.ATTR_IP_HOST) != null) fAddressControl.setText(settings.get(IPeer.ATTR_IP_HOST));
+ if (settings.get(IPeer.ATTR_IP_PORT) != null) fPortControl.setText(settings.get(IPeer.ATTR_IP_PORT));
+ if (settings.get(IPeer.ATTR_ID) != null) fPeerIdControl.setText(settings.get(IPeer.ATTR_ID));
+ if (settings.get(IPeer.ATTR_NAME) != null) fPeerNameControl.setText(settings.get(IPeer.ATTR_NAME));
+ }
+ }
+}
|