1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

[231827][remotecdt]Auto-compute default for Remote path

This commit is contained in:
Martin Oberhuber 2008-05-20 19:58:22 +00:00
parent f9470bfb50
commit 72b783e77d
6 changed files with 255 additions and 62 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.rse.remotecdt;singleton:=true
Bundle-Version: 3.0.0.qualifier
Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.rse.internal.remotecdt.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)",

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc.
* 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:
* Johann Draschwandtner (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.internal.remotecdt;
/**
* Constants used for Remote CDT connection properties.
*
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
* of a work in progress. There is no guarantee that this API will work or that
* it will remain the same. Please do not use this API without consulting with
* the <a href="http://www.eclipse.org/dsdp/tm/">Target Management</a> team.
* </p>
*
* @noimplement This interface is not intended to be implemented by clients.
* @since org.eclipse.rse.remotecdt 2.1
*/
public interface IRemoteConnectionHostConstants {
public static final String PI_REMOTE_CDT = "org.eclipse.rse.remotecdt"; //$NON-NLS-1$
public static final String REMOTE_WS_ROOT = "remoteWsRoot"; //$NON-NLS-1$
public static final String DEFAULT_SKIP_DOWNLOAD = "defaultSkipDownload"; //$NON-NLS-1$
}

View file

@ -1,13 +1,14 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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:
* Copyright (c) 2006, 2008 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:
* Martin Oberhuber (Wind River) - initial API and implementation
* Ewa Matejska (PalmSource) - [158783] browse button for cdt remote path
* Johann Draschwandtner (Wind River) - [231827][remotecdt]Auto-compute default for Remote path
*******************************************************************************/
package org.eclipse.rse.internal.remotecdt;
@ -34,6 +35,10 @@ public class Messages extends NLS {
public static String RemoteCMainTab_ErrorNoConnection;
public static String RemoteCMainTab_Connection;
public static String RemoteCMainTab_New;
public static String RemoteCMainTab_Properties;
public static String RemoteCMainTab_Properties_title;
public static String RemoteCMainTab_Properties_Location;
public static String RemoteCMainTab_Properties_Skip_default;
public static String RemoteRunLaunchDelegate_RemoteShell;
public static String RemoteRunLaunchDelegate_1;

View file

@ -1,16 +1,17 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 PalmSource, 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:
* 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:
* Ewa Matejska (PalmSource) - initial API and implementation
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
* Martin Oberhuber (Wind River) - [196934] hide disabled system types in remotecdt combo
* Yu-Fen Kuo (MontaVista) - [190613] Fix NPE in Remotecdt when RSEUIPlugin has not been loaded
* Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code
* Johann Draschwandtner (Wind River) - [231827][remotecdt]Auto-compute default for Remote path
*******************************************************************************/
package org.eclipse.rse.internal.remotecdt;
@ -26,10 +27,13 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.Window;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.IPropertySet;
import org.eclipse.rse.files.ui.dialogs.SystemRemoteFileDialog;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.ui.actions.SystemNewConnectionAction;
@ -43,25 +47,28 @@ 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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
public class RemoteCMainTab extends CMainTab {
/* Labels and Error Messages */
private static final String REMOTE_PROG_LABEL_TEXT = Messages.RemoteCMainTab_Program;
private static final String SKIP_DOWNLOAD_BUTTON_TEXT = Messages.RemoteCMainTab_SkipDownload;
private static final String REMOTE_PROG_TEXT_ERROR = Messages.RemoteCMainTab_ErrorNoProgram;
private static final String CONNECTION_TEXT_ERROR = Messages.RemoteCMainTab_ErrorNoConnection;
/* Defaults */
private static final String REMOTE_PATH_DEFAULT = EMPTY_STRING;
private static final boolean SKIP_DOWNLOAD_TO_REMOTE_DEFAULT = false;
protected Button newRemoteConnectionButton;
protected Button remoteConnectionPropertiesButton;
protected Button remoteBrowseButton;
protected Label connectionLabel;
protected Combo connectionCombo;
@ -69,15 +76,15 @@ public class RemoteCMainTab extends CMainTab {
protected Text remoteProgText;
protected Button skipDownloadButton;
protected Button useLocalPathButton;
private static int initializedRSE = 0; //0=not initialized; -1=initializing; 1=initialized
private static int initializedRSE = 0; //0=not initialized; -1=initializing; 1=initialized
SystemNewConnectionAction action = null;
public RemoteCMainTab(boolean terminalOption) {
super(terminalOption);
}
/*
* createControl
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl
@ -90,18 +97,18 @@ public class RemoteCMainTab extends CMainTab {
/* The RSE Connection dropdown with New button. */
createVerticalSpacer(comp, 1);
createRemoteConnectionGroup(comp, 3);
createRemoteConnectionGroup(comp, 4);
/* The Project and local binary location */
createVerticalSpacer(comp, 1);
createProjectGroup(comp, 1);
createExeFileGroup(comp, 1);
/* The remote binary location and skip download option */
createVerticalSpacer(comp, 1);
createTargetExePathGroup(comp);
createDownloadOption(comp);
/* If the local binary path changes, modify the remote binary location */
fProgText.addModifyListener(new ModifyListener() {
@ -113,7 +120,7 @@ public class RemoteCMainTab extends CMainTab {
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
"org.eclipse.rse.internal.remotecdt.launchgroup"); //$NON-NLS-1$
////No more needed according to https://bugs.eclipse.org/bugs/show_bug.cgi?id=178832
////No more needed according to https://bugs.eclipse.org/bugs/show_bug.cgi?id=178832
//LaunchUIPlugin.setDialogShell(parent.getShell());
}
@ -141,11 +148,11 @@ public class RemoteCMainTab extends CMainTab {
}
return retVal;
}
protected void createRemoteConnectionGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 3;
projLayout.numColumns = 4;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
projComp.setLayout(projLayout);
@ -158,7 +165,7 @@ public class RemoteCMainTab extends CMainTab {
gd = new GridData();
gd.horizontalSpan = 1;
connectionLabel.setLayoutData(gd);
connectionCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 1;
@ -168,6 +175,7 @@ public class RemoteCMainTab extends CMainTab {
public void modifyText(ModifyEvent e) {
setDirty(true);
updateLaunchConfigurationDialog();
useDefaultsFromConnection();
}
});
updateConnectionPulldown();
@ -180,10 +188,18 @@ public class RemoteCMainTab extends CMainTab {
updateLaunchConfigurationDialog();
updateConnectionPulldown();
}
});
});
remoteConnectionPropertiesButton = createPushButton(projComp, Messages.RemoteCMainTab_Properties, null);
remoteConnectionPropertiesButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
handleRemoteConnectionPropertiesSelected();
}
});
}
/*
* createTargetExePath
* This creates the remote path user-editable textfield on the Main Tab.
@ -197,13 +213,13 @@ public class RemoteCMainTab extends CMainTab {
mainComp.setLayout(mainLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
mainComp.setLayoutData(gd);
remoteProgLabel = new Label(mainComp, SWT.NONE);
remoteProgLabel.setText(REMOTE_PROG_LABEL_TEXT);
gd = new GridData();
gd.horizontalSpan = 2;
remoteProgLabel.setLayoutData(gd);
remoteProgText = new Text(mainComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 1;
@ -214,17 +230,17 @@ public class RemoteCMainTab extends CMainTab {
updateLaunchConfigurationDialog();
}
});
remoteBrowseButton = createPushButton(mainComp, Messages.RemoteCMainTab_Remote_Path_Browse_Button, null);
remoteBrowseButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
handleRemoteBrowseSelected();
updateLaunchConfigurationDialog();
}
});
}
/*
* createDownloadOption
* This creates the skip download check button.
@ -247,23 +263,23 @@ public class RemoteCMainTab extends CMainTab {
});
skipDownloadButton.setEnabled(true);
}
/*
* performApply
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply
*/
public void performApply(ILaunchConfigurationWorkingCopy config) {
int currentSelection = connectionCombo.getSelectionIndex();
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION,
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION,
currentSelection >= 0 ? connectionCombo.getItem(currentSelection) : null);
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH,
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH,
remoteProgText.getText());
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET,
config.setAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET,
skipDownloadButton.getSelection());
super.performApply(config);
}
/*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom
*/
@ -275,7 +291,7 @@ public class RemoteCMainTab extends CMainTab {
} catch (CoreException ce) {
// Ignore
}
String[] items = connectionCombo.getItems();
int i = 0;
for(i = 0; i < items.length; i++)
@ -286,20 +302,20 @@ public class RemoteCMainTab extends CMainTab {
connectionCombo.select(i);
else if(items.length > 0)
connectionCombo.select(0);
super.initializeFrom(config);
updateTargetProgFromConfig(config);
updateSkipDownloadFromConfig(config);
}
protected void handleNewRemoteConnectionSelected() {
if (action == null)
{
action = new SystemNewConnectionAction(getControl().getShell(), false, false, null);
}
try
try
{
action.run();
} catch (Exception e)
@ -319,7 +335,7 @@ public class RemoteCMainTab extends CMainTab {
break;
return connections[i];
}
protected void handleRemoteBrowseSelected() {
IHost currentConnectionSelected = getCurrentConnection();
SystemRemoteFileDialog dlg = new SystemRemoteFileDialog(getControl().getShell(),
@ -331,10 +347,81 @@ public class RemoteCMainTab extends CMainTab {
IRemoteFile selectedFile = (IRemoteFile) retObj;
remoteProgText.setText(selectedFile.getAbsolutePath());
}
}
}
protected void handleRemoteConnectionPropertiesSelected() {
class RemoteConnectionPropertyDialog extends Dialog {
private IHost fHost;
boolean fbLocalHost;
private Button fSkipDownloadBtn;
private Text fWSRoot;
public RemoteConnectionPropertyDialog(Shell parentShell, String dialogTitle, IHost host) {
super(parentShell);
parentShell.setText(dialogTitle);
fHost = host;
fbLocalHost = fHost.getSystemType().isLocal();
}
protected Control createDialogArea(Composite parent) {
// create composite
Composite composite = (Composite) super.createDialogArea(parent);
Label label = new Label(composite, SWT.WRAP);
label.setText(Messages.RemoteCMainTab_Properties_Location);
GridData data = new GridData(GridData.GRAB_HORIZONTAL
| GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
| GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
fWSRoot = new Text(composite, SWT.SINGLE | SWT.BORDER);
fWSRoot.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
fSkipDownloadBtn = new Button(composite, SWT.CHECK);
fSkipDownloadBtn.setText(Messages.RemoteCMainTab_Properties_Skip_default);
if(!fbLocalHost) {
IPropertySet propertySet = fHost.getPropertySet(IRemoteConnectionHostConstants.PI_REMOTE_CDT);
if (propertySet != null) {
String value = propertySet.getPropertyValue(IRemoteConnectionHostConstants.REMOTE_WS_ROOT);
if(value != null) {
fWSRoot.setText(value);
}
fSkipDownloadBtn.setSelection(Boolean.valueOf(propertySet.getPropertyValue(IRemoteConnectionHostConstants.DEFAULT_SKIP_DOWNLOAD))
.booleanValue());
}
} else {
fSkipDownloadBtn.setEnabled(false);
fWSRoot.setEnabled(false);
}
applyDialogFont(composite);
return composite;
}
protected void buttonPressed(int buttonId) {
if(!fbLocalHost && (buttonId == IDialogConstants.OK_ID)) {
IPropertySet propertySet = fHost.getPropertySet(IRemoteConnectionHostConstants.PI_REMOTE_CDT);
if (propertySet == null) {
propertySet = fHost.createPropertySet(IRemoteConnectionHostConstants.PI_REMOTE_CDT);
}
propertySet.addProperty(IRemoteConnectionHostConstants.REMOTE_WS_ROOT, fWSRoot.getText());
propertySet.addProperty(IRemoteConnectionHostConstants.DEFAULT_SKIP_DOWNLOAD, Boolean.toString(fSkipDownloadBtn.getSelection()));
fHost.commit();
}
super.buttonPressed(buttonId);
}
}
IHost currentConnectionSelected = getCurrentConnection();
RemoteConnectionPropertyDialog dlg = new RemoteConnectionPropertyDialog(getControl().getShell(),
Messages.RemoteCMainTab_Properties_title, currentConnectionSelected);
dlg.setBlockOnOpen(true);
dlg.open();
}
private void waitForRSEInit(final Runnable callback) {
Job initRSEJob = null;
Job[] jobs = Job.getJobManager().find(null);
@ -367,7 +454,7 @@ public class RemoteCMainTab extends CMainTab {
waitForRestoreCompleteJob.schedule();
}
}
protected void updateConnectionPulldown() {
if (initializedRSE==0) {
// start RSEUIPlugin to make sure the SystemRegistry is initialized.
@ -393,12 +480,12 @@ public class RemoteCMainTab extends CMainTab {
connectionCombo.add(connections[i].getAliasName());
}
}
if(connections.length > 0)
connectionCombo.select(connections.length - 1);
}
}
protected void updateTargetProgFromConfig(ILaunchConfiguration config) {
String targetPath = null;
try {
@ -409,34 +496,99 @@ public class RemoteCMainTab extends CMainTab {
}
remoteProgText.setText(targetPath);
}
protected void updateSkipDownloadFromConfig(ILaunchConfiguration config) {
boolean downloadToTarget = true;
try {
downloadToTarget = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET,
downloadToTarget = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET,
SKIP_DOWNLOAD_TO_REMOTE_DEFAULT);
} catch (CoreException e) {
// Ignore for now
}
skipDownloadButton.setSelection(downloadToTarget);
}
/*
* setLocalPathForRemotePath
* This function sets the remote path text field with the value of the
* This function sets the remote path text field with the value of the
* local executable path.
*/
private void setLocalPathForRemotePath() {
String programName = fProgText.getText().trim();
boolean bUpdateRemote = false;
String remoteName = remoteProgText.getText().trim();
if (programName.length() != 0 && remoteName.length() == 0) {
String remoteWsRoot = getRemoteWSRoot();
if(remoteName.length() == 0) {
bUpdateRemote = true;
} else if(remoteWsRoot.length() != 0){
bUpdateRemote = remoteName.equals(remoteWsRoot);
}
if (programName.length() != 0 && bUpdateRemote) {
IProject project = getCProject().getProject();
IPath exePath = new Path(programName);
if (!exePath.isAbsolute()) {
exePath = project.getFile(programName).getLocation();
IPath wsRoot = project.getWorkspace().getRoot().getLocation();
exePath = makeRelativeToWSRootLocation(exePath, remoteWsRoot, wsRoot);
}
String path = exePath.toString();
remoteProgText.setText(path);
}
}
private void useDefaultsFromConnection() {
if((remoteProgText != null) && !remoteProgText.isDisposed()) {
String remoteName = remoteProgText.getText().trim();
String remoteWsRoot = getRemoteWSRoot();
if(remoteName.length() == 0) {
remoteProgText.setText(remoteWsRoot);
} else {
// try to use remote path
IPath wsRoot = getCProject().getProject().getWorkspace().getRoot().getLocation();
IPath remotePath = makeRelativeToWSRootLocation(new Path(remoteName), remoteWsRoot, wsRoot);
remoteProgText.setText(remotePath.toString());
}
}
if((skipDownloadButton != null) && !skipDownloadButton.isDisposed()) {
skipDownloadButton.setSelection(getDefaultSkipDownload());
}
}
private IPath makeRelativeToWSRootLocation(IPath exePath, String remoteWsRoot, IPath wsRoot) {
if(remoteWsRoot.length() != 0) {
// use remoteWSRoot instead of Workspace Root
if(wsRoot.isPrefixOf(exePath)) {
return new Path(remoteWsRoot).append(exePath.removeFirstSegments(wsRoot.segmentCount()).setDevice(null));
}
}
return exePath;
}
private String getRemoteWSRoot() {
IHost host = getCurrentConnection();
if(host != null) {
IPropertySet propertySet = host.getPropertySet(IRemoteConnectionHostConstants.PI_REMOTE_CDT);
if (propertySet != null) {
String value = propertySet.getPropertyValue(IRemoteConnectionHostConstants.REMOTE_WS_ROOT);
if(value != null) {
return value;
}
}
}
return ""; //$NON-NLS-1$
}
private boolean getDefaultSkipDownload() {
IHost host = getCurrentConnection();
if(host != null) {
IPropertySet propertySet = host.getPropertySet(IRemoteConnectionHostConstants.PI_REMOTE_CDT);
if (propertySet != null) {
return Boolean.valueOf(propertySet.getPropertyValue(IRemoteConnectionHostConstants.DEFAULT_SKIP_DOWNLOAD)).booleanValue();
}
}
return SKIP_DOWNLOAD_TO_REMOTE_DEFAULT;
}
}

View file

@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
# Copyright (c) 2006, 2008 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
@ -8,6 +8,7 @@
# Contributors:
# Martin Oberhuber (Wind River) - externalized strings
# Ewa Matejska (PalmSource) - [158783] browse button for cdt remote path
# Johann Draschwandtner (Wind River) - [231827][remotecdt]Auto-compute default for Remote path
################################################################################
# NLS_MESSAGEFORMAT_VAR
@ -32,3 +33,7 @@ Gdbserver_Settings_Tab_Name=Gdbserver Settings
Gdbserver_name_textfield_label=Gdbserver name:
Port_number_textfield_label=Port number:
RemoteCMainTab_Remote_Path_Browse_Button_Title=Select Remote C/C++ Application File
RemoteCMainTab_Properties=Properties...
RemoteCMainTab_Properties_title=Properties
RemoteCMainTab_Properties_Location=Remote workspace location:
RemoteCMainTab_Properties_Skip_default=Skip download to target path by default

View file

@ -2,7 +2,7 @@
<feature
id="org.eclipse.rse.remotecdt"
label="%featureName"
version="3.0.0.qualifier"
version="2.1.0.qualifier"
provider-name="%providerName"
plugin="org.eclipse.rse.remotecdt"
image="eclipse_update_120.jpg">