1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

[216858] Need the ability to Import/Export RSE connections for sharing

https://bugs.eclipse.org/bugs/show_bug.cgi?id=216858
This commit is contained in:
David Dykstal 2008-04-28 18:03:12 +00:00
parent b715b90eff
commit 8e5e935608
10 changed files with 323 additions and 45 deletions

View file

@ -13,6 +13,7 @@
* David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared * David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model * David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
* David Dykstal (IBM) - [189274] provide import and export operations for profiles * David Dykstal (IBM) - [189274] provide import and export operations for profiles
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.core; package org.eclipse.rse.internal.core;
@ -50,6 +51,7 @@ public class RSECoreMessages extends NLS {
public static String PropertyFileProvider_SavingTaskName; public static String PropertyFileProvider_SavingTaskName;
public static String PropertyFileProvider_UnexpectedException; public static String PropertyFileProvider_UnexpectedException;
public static String RSEEnvelope_ExportNotSupported; public static String RSEEnvelope_ExportNotSupported;
public static String RSEEnvelope_IncorrectFormat;
public static String RSEEnvelope_ModelNotExported; public static String RSEEnvelope_ModelNotExported;
public static String RSEPersistenceManager_DeleteProfileJobName; public static String RSEPersistenceManager_DeleteProfileJobName;
public static String SaveRSEDOMJob_SavingProfileJobName; public static String SaveRSEDOMJob_SavingProfileJobName;

View file

@ -15,6 +15,7 @@
# David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared # David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared
# David Dykstal (IBM) - [189274] provide import and export operations for profiles # David Dykstal (IBM) - [189274] provide import and export operations for profiles
# Xuan Chen (IBM) - [226355] [NL] Need to update the tooltip for switching to online for a connection # Xuan Chen (IBM) - [226355] [NL] Need to update the tooltip for switching to online for a connection
# David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
############################################################################### ###############################################################################
# NLS_MESSAGEFORMAT_VAR # NLS_MESSAGEFORMAT_VAR
@ -42,6 +43,7 @@ RESID_PROPERTYSET_LAUNCHER_PROPERTIES=Launcher Properties
# Persistence # Persistence
RSEEnvelope_ExportNotSupported=The persistence provider does not support export. RSEEnvelope_ExportNotSupported=The persistence provider does not support export.
RSEEnvelope_IncorrectFormat=Incorrect file format
RSEEnvelope_ModelNotExported=The persistence provider did not export the model. RSEEnvelope_ModelNotExported=The persistence provider did not export the model.
RSEPersistenceManager_DeleteProfileJobName=Delete RSE Profile Job RSEPersistenceManager_DeleteProfileJobName=Delete RSE Profile Job
PropertyFileProvider_SavingTaskName=Saving DOM PropertyFileProvider_SavingTaskName=Saving DOM

View file

@ -7,6 +7,7 @@
* Contributors: * Contributors:
* David Dykstal (IBM) - initial contribution. * David Dykstal (IBM) - initial contribution.
* David Dykstal (IBM) - [189274] provide import and export operations for profiles * David Dykstal (IBM) - [189274] provide import and export operations for profiles
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
*********************************************************************************/ *********************************************************************************/
package org.eclipse.rse.internal.persistence; package org.eclipse.rse.internal.persistence;
@ -28,6 +29,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -36,6 +38,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.rse.core.IRSECoreStatusCodes;
import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.filters.ISystemFilterPool;
import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
@ -61,6 +64,10 @@ import org.eclipse.rse.persistence.dom.RSEDOMNode;
*/ */
public class RSEEnvelope { public class RSEEnvelope {
// IStatus is immutable so we can do this safely
private static IStatus INVALID_FORMAT = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, IRSECoreStatusCodes.INVALID_FORMAT, RSECoreMessages.RSEEnvelope_IncorrectFormat, null);
private static IStatus MODEL_NOT_EXPORTED = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, RSECoreMessages.RSEEnvelope_ModelNotExported);
private RSEDOM dom = null; private RSEDOM dom = null;
/** /**
@ -71,28 +78,42 @@ public class RSEEnvelope {
/** /**
* Replaces the contents of this envelope with the contents found on the input stream. * Replaces the contents of this envelope with the contents found on the input stream.
* The format of the stream is determined by the persistence provider used to write the contents fo that stream. * The format of the stream is determined by the persistence provider used to write the contents of that stream.
* The stream is closed at the end of the operation. * The stream is closed at the end of the operation.
* This operation is performed in the thread of the caller. * This operation is performed in the thread of the caller.
* If asynchronous operation is desired place this invocation inside a job. * If asynchronous operation is desired place this invocation inside a job.
* @param in the input stream which is read into the envelope. * @param in the input stream which is read into the envelope.
* @param monitor a monitor used for tracking progress and cancelation. * @param monitor a monitor used for tracking progress and cancelation.
* If the monitor is cancelled this envelope will be empty. * If the monitor is cancelled this envelope will be empty.
* @throws IOException should one occur manipulating the stream. * @throws CoreException if a problem occur reading the stream.
*/ */
public void get(InputStream in, IProgressMonitor monitor) throws IOException { public void get(InputStream in, IProgressMonitor monitor) throws CoreException {
File envelopeFolder = getTemporaryFolder(); File envelopeFolder = getTemporaryFolder();
unzip(in, envelopeFolder); IStatus status = unzip(in, envelopeFolder);
String providerId = loadProviderId(envelopeFolder); if (status.isOK()) {
IRSEPersistenceManager manager = RSECorePlugin.getThePersistenceManager(); String providerId = loadProviderId(envelopeFolder);
IRSEPersistenceProvider provider = manager.getPersistenceProvider(providerId); IRSEPersistenceManager manager = RSECorePlugin.getThePersistenceManager();
if (provider != null) { IRSEPersistenceProvider provider = manager.getPersistenceProvider(providerId);
if (provider instanceof IRSEImportExportProvider) { if (provider != null) {
IRSEImportExportProvider ieProvider = (IRSEImportExportProvider) provider; if (provider instanceof IRSEImportExportProvider) {
dom = ieProvider.importRSEDOM(envelopeFolder, monitor); IRSEImportExportProvider ieProvider = (IRSEImportExportProvider) provider;
dom = ieProvider.importRSEDOM(envelopeFolder, monitor);
if (dom == null) {
status = INVALID_FORMAT;
}
} else {
// invalid format due to bad persistence provider specfied
status = INVALID_FORMAT;
}
} else {
// invalid format due to provider not installed in this workbench
status = INVALID_FORMAT;
} }
} }
deleteFileSystemObject(envelopeFolder); deleteFileSystemObject(envelopeFolder);
if (!status.isOK()) {
throw new CoreException(status);
}
} }
/** /**
@ -122,10 +143,10 @@ public class RSEEnvelope {
} }
deleteFileSystemObject(envelopeFolder); deleteFileSystemObject(envelopeFolder);
} else { } else {
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, RSECoreMessages.RSEEnvelope_ModelNotExported); status = MODEL_NOT_EXPORTED;
} }
} else { } else {
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, RSECoreMessages.RSEEnvelope_ExportNotSupported); status = MODEL_NOT_EXPORTED;
} }
try { try {
out.close(); out.close();
@ -254,12 +275,13 @@ public class RSEEnvelope {
private IHost mergeHost(ISystemProfile profile, RSEDOMNode hostNode) { private IHost mergeHost(ISystemProfile profile, RSEDOMNode hostNode) {
IHost host = null; IHost host = null;
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
String hostName = hostNode.getName(); String baseHostName = hostNode.getName();
String hostName = baseHostName;
if (registry.getHost(profile, hostName) != null) { if (registry.getHost(profile, hostName) != null) {
int n = 0; int n = 0;
while (registry.getHost(profile, hostName) != null) { while (registry.getHost(profile, hostName) != null) {
n++; n++;
hostName = hostName + "-" + n; //$NON-NLS-1$ hostName = baseHostName + "-" + n; //$NON-NLS-1$
} }
hostNode.setName(hostName); hostNode.setName(hostName);
} }
@ -316,7 +338,7 @@ public class RSEEnvelope {
return status; return status;
} }
private String loadProviderId(File parent) { private String loadProviderId(File parent) throws CoreException {
String providerId = null; String providerId = null;
File idFile = new File(parent, "provider.id"); //$NON-NLS-1$ File idFile = new File(parent, "provider.id"); //$NON-NLS-1$
try { try {
@ -324,6 +346,8 @@ public class RSEEnvelope {
providerId = in.readLine(); providerId = in.readLine();
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
IStatus status = INVALID_FORMAT;
throw new CoreException(status);
} }
return providerId; return providerId;
} }
@ -432,11 +456,19 @@ public class RSEEnvelope {
} }
entry = inZip.getNextEntry(); entry = inZip.getNextEntry();
} }
inZip.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
status = makeStatus(e); status = makeStatus(e);
} catch (ZipException e) {
RSECorePlugin.getDefault().getLogger().logError(RSECoreMessages.RSEEnvelope_IncorrectFormat, e);
status = INVALID_FORMAT;
} catch (IOException e) { } catch (IOException e) {
status = makeStatus(e); status = makeStatus(e);
} finally {
try {
in.close();
} catch (IOException e) {
status = makeStatus(e);
}
} }
return status; return status;
} }
@ -460,7 +492,7 @@ public class RSEEnvelope {
} }
private IStatus makeStatus(Exception e) { private IStatus makeStatus(Exception e) {
IStatus status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, "Unexpected Exception", e); //$NON-NLS-1$ IStatus status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, "Unexpected exception", e); //$NON-NLS-1$
return status; return status;
} }

View file

@ -20,6 +20,7 @@
* Rupen Mardirossian (IBM) - [210682] Added BUTTON_OVERWRITE_ALL & and tooltip, also added some verbiage for new SystemCopyDialog. * Rupen Mardirossian (IBM) - [210682] Added BUTTON_OVERWRITE_ALL & and tooltip, also added some verbiage for new SystemCopyDialog.
* Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View * Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View
* David Dykstal (IBM) - [210242] Credentials dialog should look different if password is not supported or optional * David Dykstal (IBM) - [210242] Credentials dialog should look different if password is not supported or optional
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.ui; package org.eclipse.rse.internal.ui;
@ -1000,14 +1001,38 @@ public class SystemResources extends NLS
public static String RESID_HOST_ENCODING_OTHER_TOOLTIP; public static String RESID_HOST_ENCODING_OTHER_TOOLTIP;
public static String RESID_HOST_ENCODING_ENTER_TOOLTIP; public static String RESID_HOST_ENCODING_ENTER_TOOLTIP;
public static String RESID_IMPORT_CONNECTION_ACTION_INVALID_FORMAT;
public static String RESID_IMPORT_CONNECTION_ACTION_LABEL; public static String RESID_IMPORT_CONNECTION_ACTION_LABEL;
public static String RESID_IMPORT_CONNECTION_ACTION_READER_MISSING;
public static String RESID_IMPORT_CONNECTION_ACTION_TOOLTIP; public static String RESID_IMPORT_CONNECTION_ACTION_TOOLTIP;
public static String RESID_IMPORT_CONNECTION_LABEL_LONG;
public static String SystemExportConnectionAction_CoreExceptionFound;
public static String SystemExportConnectionAction_Error;
public static String SystemExportConnectionAction_ExportJobName;
public static String SystemExportConnectionAction_OverwriteFileCondition;
public static String SystemExportConnectionAction_UnexpectedException;
public static String SystemExportConnectionAction_Warning;
public static String SystemExportConnectionAction_WriteProtectedFileCondition;
public static String SystemImportConnectionAction_CoreExceptionFound;
public static String SystemImportConnectionAction_Error;
public static String SystemImportConnectionAction_FileNotFoundCondition;
public static String SystemImportConnectionAction_FileNotReadableCondition;
public static String SystemImportConnectionAction_ImportJobName;
public static String SystemImportConnectionAction_UnexpectedException;
static { static {
// load message values from bundle file // load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, SystemResources.class); NLS.initializeMessages(BUNDLE_NAME, SystemResources.class);

View file

@ -22,6 +22,7 @@
# Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View # Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View
# David Dykstal (IBM) - [197018] Last Page of New Filter Wizard mentions Change Action # David Dykstal (IBM) - [197018] Last Page of New Filter Wizard mentions Change Action
# David Dykstal (IBM) - [210242] Credentials dialog should look different if password is not supported or optional # David Dykstal (IBM) - [210242] Credentials dialog should look different if password is not supported or optional
# David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
################################################################################ ################################################################################
# NLS_MESSAGEFORMAT_VAR # NLS_MESSAGEFORMAT_VAR
@ -1053,7 +1054,7 @@ RESID_SERVICESFORM_PROPERTIES_TOOLTIP=Edit the properties of the item selected i
## Do not show this message again ## Do not show this message again
RESID_DO_NOT_SHOW_MESSAGE_AGAIN_LABEL = Do not show this message again RESID_DO_NOT_SHOW_MESSAGE_AGAIN_LABEL = Do not show this message again
RESID_DO_NOT_SHOW_MESSAGE_AGAIN_TOOLTIP = Select this option if you do not want to see this message again RESID_DO_NOT_SHOW_MESSAGE_AGAIN_TOOLTIP = Select this option if you do not want to see this message again
RESID_EXPORT_CONNECTION_ACTIONS_TOOLTIP=Export connection definitions RESID_EXPORT_CONNECTION_ACTIONS_TOOLTIP=Export connection definition
RESID_EXPORT_CONNECTIONS_ACTION_LABEL=Export... RESID_EXPORT_CONNECTIONS_ACTION_LABEL=Export...
# Strings for Encodings # Strings for Encodings
@ -1066,7 +1067,19 @@ RESID_HOST_ENCODING_REMOTE_TOOLTIP=The default encoding of the platform obtained
RESID_HOST_ENCODING_OTHER_LABEL=Other: RESID_HOST_ENCODING_OTHER_LABEL=Other:
RESID_HOST_ENCODING_OTHER_TOOLTIP=Specify a different encoding RESID_HOST_ENCODING_OTHER_TOOLTIP=Specify a different encoding
RESID_HOST_ENCODING_ENTER_TOOLTIP=Select or enter an encoding RESID_HOST_ENCODING_ENTER_TOOLTIP=Select or enter an encoding
RESID_IMPORT_CONNECTION_ACTION_INVALID_FORMAT=The selected file is not of the correct format to be imported.
RESID_IMPORT_CONNECTION_ACTION_LABEL=Import... RESID_IMPORT_CONNECTION_ACTION_LABEL=Import...
RESID_IMPORT_CONNECTION_ACTION_READER_MISSING=The reader for this file format is not installed. RESID_IMPORT_CONNECTION_ACTION_TOOLTIP=Import connection definition
RESID_IMPORT_CONNECTION_ACTION_TOOLTIP=Import connection definitions RESID_IMPORT_CONNECTION_LABEL_LONG=Import Connection...
SystemExportConnectionAction_CoreExceptionFound=Core exception found during export.
SystemExportConnectionAction_Error=Error
SystemExportConnectionAction_ExportJobName=RSE Connection Export Job
SystemExportConnectionAction_OverwriteFileCondition=The file {0} already exists. Click OK to overwrite it.
SystemExportConnectionAction_UnexpectedException=unexpected exception
SystemExportConnectionAction_Warning=Warning
SystemExportConnectionAction_WriteProtectedFileCondition=The file {0} is write protected.
SystemImportConnectionAction_CoreExceptionFound=Core exception found during import.
SystemImportConnectionAction_Error=Error
SystemImportConnectionAction_FileNotFoundCondition=File {0} does not exist.
SystemImportConnectionAction_FileNotReadableCondition=You do not have permission to read file {0}.
SystemImportConnectionAction_ImportJobName=RSE Connection Import Job
SystemImportConnectionAction_UnexpectedException=unexpected exception

View file

@ -10,36 +10,125 @@
package org.eclipse.rse.internal.ui.actions; package org.eclipse.rse.internal.ui.actions;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.internal.persistence.RSEEnvelope;
import org.eclipse.rse.internal.ui.SystemResources; import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.persistence.IRSEPersistenceManager;
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
import org.eclipse.rse.ui.ISystemContextMenuConstants; import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemBasePlugin;
import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.actions.SystemBaseAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import com.ibm.icu.text.MessageFormat;
/** /**
* This is the action for clearing in-memory userId and password cache * This is the action for exporting a connection to a file.
*/ */
public class SystemExportConnectionAction extends SystemBaseAction { public class SystemExportConnectionAction extends SystemBaseAction {
private class ExportJob extends Job {
private File outFile;
private IHost host;
public ExportJob(IHost host, File outFile) {
super(SystemResources.SystemExportConnectionAction_ExportJobName);
this.outFile = outFile;
this.host = host;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
IRSEPersistenceManager manager = RSECorePlugin.getThePersistenceManager();
IRSEPersistenceProvider persistenceProvider = manager.getPersistenceProvider("org.eclipse.rse.persistence.PropertyFileProvider"); //$NON-NLS-1$
RSEEnvelope envelope = new RSEEnvelope();
envelope.add(host);
try {
FileOutputStream out = new FileOutputStream(outFile);
envelope.put(out, persistenceProvider, monitor);
out.close();
} catch (FileNotFoundException e) {
// should not happen, log as unexpected
SystemBasePlugin.logError(SystemResources.SystemExportConnectionAction_UnexpectedException, e);
} catch (CoreException e) {
// log the exception and return the status code
SystemBasePlugin.logError(SystemResources.SystemExportConnectionAction_CoreExceptionFound, e);
status = e.getStatus();
} catch (IOException e) {
// should not happend, log as unexpected
SystemBasePlugin.logError(SystemResources.SystemExportConnectionAction_UnexpectedException, e);
}
return status;
}
}
/** /**
* Constructor. * Constructor.
*/ */
public SystemExportConnectionAction() { public SystemExportConnectionAction() {
super(SystemResources.RESID_EXPORT_CONNECTIONS_ACTION_LABEL, SystemResources.RESID_EXPORT_CONNECTION_ACTIONS_TOOLTIP, null); super(SystemResources.RESID_EXPORT_CONNECTIONS_ACTION_LABEL, SystemResources.RESID_EXPORT_CONNECTION_ACTIONS_TOOLTIP, null);
setContextMenuGroup(ISystemContextMenuConstants.GROUP_CONNECTION); setContextMenuGroup(ISystemContextMenuConstants.GROUP_REORGANIZE);
setHelp(RSEUIPlugin.HELPPREFIX + "ActionExportConnectionDefinitions"); //$NON-NLS-1$ setHelp(RSEUIPlugin.HELPPREFIX + "ActionExportConnectionDefinitions"); //$NON-NLS-1$
} }
/** /**
* The export password action is enabled when the selection contains only connections (hosts) * The export connection action is enabled when the selection contains only connections (hosts)
*/ */
public boolean checkObjectType(Object obj) { public boolean checkObjectType(Object obj) {
return true; boolean result = obj instanceof IHost;
return result;
} }
/** /**
* Called when this action is selection from the popup menu. * Called when this action is selection from the popup menu.
*/ */
public void run() { public void run() {
// TODO DWD implement FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
String path = saveDialog.open();
if (path != null) {
File outFile = new File(path);
boolean ok = true;
if (outFile.exists()) {
if (outFile.canWrite()) {
String title = SystemResources.SystemExportConnectionAction_Warning;
String message = MessageFormat.format(SystemResources.SystemExportConnectionAction_OverwriteFileCondition, new String[] {path});
ok = MessageDialog.openConfirm(shell, title, message);
} else {
String title = SystemResources.SystemExportConnectionAction_Error;
String message = MessageFormat.format(SystemResources.SystemExportConnectionAction_WriteProtectedFileCondition, new String[] {path});
MessageDialog.openError(shell, title, message);
ok = false;
}
}
if (ok) {
IStructuredSelection selection = getSelection();
Assert.isTrue(selection.size() == 1, "selection size should be one"); //$NON-NLS-1$
IHost host = (IHost) selection.getFirstElement();
Job exportJob = new ExportJob(host, outFile);
exportJob.schedule();
}
}
} }
} }

View file

@ -10,45 +10,128 @@
package org.eclipse.rse.internal.ui.actions; package org.eclipse.rse.internal.ui.actions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.ISystemProfileManager;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.internal.persistence.RSEEnvelope;
import org.eclipse.rse.internal.ui.SystemResources; import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage;
import org.eclipse.rse.ui.ISystemContextMenuConstants; import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemBasePlugin;
import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.actions.SystemBaseAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import com.ibm.icu.text.MessageFormat;
/** /**
* This action is used to import a connection from its package file into the default profile. * This action is used to import a connection from a file into the selected profile.
*/ */
public class SystemImportConnectionAction extends SystemBaseAction { public class SystemImportConnectionAction extends SystemBaseAction {
private static final SimpleSystemMessage error1 = new SimpleSystemMessage(RSEUIPlugin.PLUGIN_ID, IStatus.ERROR, SystemResources.RESID_IMPORT_CONNECTION_ACTION_INVALID_FORMAT); private class ImportJob extends Job {
private static final SimpleSystemMessage error2 = new SimpleSystemMessage(RSEUIPlugin.PLUGIN_ID, IStatus.ERROR, SystemResources.RESID_IMPORT_CONNECTION_ACTION_READER_MISSING);
private ISystemProfile profile = null;
private File inFile = null;
public ImportJob(File inFile, ISystemProfile profile) {
super(SystemResources.SystemImportConnectionAction_ImportJobName);
this.inFile = inFile;
this.profile = profile;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
RSEEnvelope envelope = new RSEEnvelope();
try {
FileInputStream in = new FileInputStream(inFile);
envelope.get(in, monitor);
envelope.mergeWith(profile);
} catch (FileNotFoundException e) {
// should not happen, log as unexpected
SystemBasePlugin.logError(SystemResources.SystemImportConnectionAction_UnexpectedException, e);
} catch (CoreException e) {
// log the exception and return the status code
status = e.getStatus();
String message = status.getMessage();
if (message == null) {
message = SystemResources.SystemImportConnectionAction_CoreExceptionFound;
}
SystemBasePlugin.logError(message, e);
}
return status;
}
}
/** /**
* Creates a new action to import a connection into a profile. * Creates a new action to import a connection into a profile.
*/ */
public SystemImportConnectionAction() { public SystemImportConnectionAction() {
super(SystemResources.RESID_IMPORT_CONNECTION_ACTION_LABEL, SystemResources.RESID_IMPORT_CONNECTION_ACTION_TOOLTIP, null); super(SystemResources.RESID_IMPORT_CONNECTION_ACTION_LABEL, SystemResources.RESID_IMPORT_CONNECTION_ACTION_TOOLTIP, null);
setContextMenuGroup(ISystemContextMenuConstants.GROUP_CONNECTION); setContextMenuGroup(ISystemContextMenuConstants.GROUP_REORGANIZE);
setHelp(RSEUIPlugin.HELPPREFIX + "ActionImportConnectionDefinitions"); //$NON-NLS-1$ setHelp(RSEUIPlugin.HELPPREFIX + "ActionImportConnectionDefinitions"); //$NON-NLS-1$
} }
/** /**
* The import action can be run no matter what the selection is. * The import action can be run if the selection contains profiles or hosts.
* @return true * @return true if the selection contains a profile or a host.
*/ */
public boolean checkObjectType(Object obj) { public boolean checkObjectType(Object obj) {
return true; return (obj instanceof ISystemProfile || obj instanceof IHost);
} }
/** /**
* Called when this action is selection from the popup menu. * Called when this action is selection from the popup menu.
*/ */
public void run() { public void run() {
// TODO DWD implement FileDialog openDialog = new FileDialog(shell, SWT.OPEN);
String path = openDialog.open();
if (path != null) {
File inFile = new File(path);
if (inFile.exists()) {
if (inFile.canRead()) {
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
ISystemProfileManager profileManager = registry.getSystemProfileManager();
ISystemProfile profile = profileManager.getDefaultPrivateSystemProfile();
IStructuredSelection selection = getSelection();
if (selection != null && selection.size() > 0) {
Object selected = getFirstSelection();
if (selected instanceof IHost) {
profile = ((IHost)selected).getSystemProfile();
} else if (selected instanceof ISystemProfile) {
profile = (ISystemProfile) selected;
}
}
ImportJob importJob = new ImportJob(inFile, profile);
importJob.schedule();
} else {
String title = SystemResources.SystemImportConnectionAction_Error;
String message = MessageFormat.format(SystemResources.SystemImportConnectionAction_FileNotReadableCondition, new String[] {path});
MessageDialog.openError(shell, title, message);
}
} else {
String title = SystemResources.SystemImportConnectionAction_Error;
String message = MessageFormat.format(SystemResources.SystemImportConnectionAction_FileNotFoundCondition, new String[] {path});
MessageDialog.openError(shell, title, message);
}
}
} }
} }

View file

@ -52,6 +52,7 @@
* David McKnight (IBM) - [224380] system view should only fire property sheet update event when in focus * David McKnight (IBM) - [224380] system view should only fire property sheet update event when in focus
* David McKnight (IBM) - [224313] [api] Create RSE Events for MOVE and COPY holding both source and destination fields * David McKnight (IBM) - [224313] [api] Create RSE Events for MOVE and COPY holding both source and destination fields
* David Dykstal (IBM) - [225911] Exception received after deleting a profile containing a connection * David Dykstal (IBM) - [225911] Exception received after deleting a profile containing a connection
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.ui.view; package org.eclipse.rse.internal.ui.view;
@ -135,6 +136,7 @@ import org.eclipse.rse.internal.ui.actions.SystemCommonDeleteAction;
import org.eclipse.rse.internal.ui.actions.SystemCommonRenameAction; import org.eclipse.rse.internal.ui.actions.SystemCommonRenameAction;
import org.eclipse.rse.internal.ui.actions.SystemCommonSelectAllAction; import org.eclipse.rse.internal.ui.actions.SystemCommonSelectAllAction;
import org.eclipse.rse.internal.ui.actions.SystemExpandAction; import org.eclipse.rse.internal.ui.actions.SystemExpandAction;
import org.eclipse.rse.internal.ui.actions.SystemImportConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemOpenExplorerPerspectiveAction; import org.eclipse.rse.internal.ui.actions.SystemOpenExplorerPerspectiveAction;
import org.eclipse.rse.internal.ui.actions.SystemShowInMonitorAction; import org.eclipse.rse.internal.ui.actions.SystemShowInMonitorAction;
import org.eclipse.rse.internal.ui.actions.SystemShowInTableAction; import org.eclipse.rse.internal.ui.actions.SystemShowInTableAction;
@ -228,6 +230,7 @@ public class SystemView extends SafeTreeViewer
// protected actions initialized on demand: // protected actions initialized on demand:
// should be accessed by getters only // should be accessed by getters only
private SystemNewConnectionAction _newConnectionAction; private SystemNewConnectionAction _newConnectionAction;
private SystemImportConnectionAction _importConnectionAction;
private SystemRefreshAction _refreshAction; private SystemRefreshAction _refreshAction;
private PropertyDialogAction _propertyDialogAction; private PropertyDialogAction _propertyDialogAction;
private SystemCollapseAction _collapseAction; // defect 41203 private SystemCollapseAction _collapseAction; // defect 41203
@ -666,6 +669,19 @@ public class SystemView extends SafeTreeViewer
return _newConnectionAction; return _newConnectionAction;
} }
/**
* Rather than pre-defining this common action we wait until it is first needed,
* for performance reasons.
*/
private IAction getImportConnectionAction() {
if (_importConnectionAction == null) {
_importConnectionAction = new SystemImportConnectionAction(); // true=>from popup menu
_importConnectionAction.setShell(getShell());
_importConnectionAction.setText(SystemResources.RESID_IMPORT_CONNECTION_LABEL_LONG);
}
return _importConnectionAction;
}
/** /**
* Return the refresh action * Return the refresh action
*/ */
@ -826,6 +842,7 @@ public class SystemView extends SafeTreeViewer
if (selectionCount == 0) // nothing selected if (selectionCount == 0) // nothing selected
{ {
menu.add(getNewConnectionAction()); menu.add(getNewConnectionAction());
menu.add(getImportConnectionAction());
menu.add(new GroupMarker(ISystemContextMenuConstants.GROUP_ADDITIONS)); // user or BP/ISV additions menu.add(new GroupMarker(ISystemContextMenuConstants.GROUP_ADDITIONS)); // user or BP/ISV additions
} else { } else {
if (selectionCount > 1) { if (selectionCount > 1) {

View file

@ -32,6 +32,7 @@
* Martin Oberhuber (Wind River) - [216266] Consider stateless subsystems (supportsSubSystemConnect==false) * Martin Oberhuber (Wind River) - [216266] Consider stateless subsystems (supportsSubSystemConnect==false)
* David Dykstal (IBM) - [197036] minor refactoring caused by SystemRegistry fix for this bug * David Dykstal (IBM) - [197036] minor refactoring caused by SystemRegistry fix for this bug
* Martin Oberhuber (Wind River) - [215820] Move SystemRegistry implementation to Core * Martin Oberhuber (Wind River) - [215820] Move SystemRegistry implementation to Core
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.ui.view; package org.eclipse.rse.internal.ui.view;
@ -57,6 +58,8 @@ import org.eclipse.rse.internal.ui.actions.SystemClearAllPasswordsAction;
import org.eclipse.rse.internal.ui.actions.SystemConnectAllSubSystemsAction; import org.eclipse.rse.internal.ui.actions.SystemConnectAllSubSystemsAction;
import org.eclipse.rse.internal.ui.actions.SystemCopyConnectionAction; import org.eclipse.rse.internal.ui.actions.SystemCopyConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemDisconnectAllSubSystemsAction; import org.eclipse.rse.internal.ui.actions.SystemDisconnectAllSubSystemsAction;
import org.eclipse.rse.internal.ui.actions.SystemExportConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemImportConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemMoveConnectionAction; import org.eclipse.rse.internal.ui.actions.SystemMoveConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemMoveDownConnectionAction; import org.eclipse.rse.internal.ui.actions.SystemMoveDownConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemMoveUpConnectionAction; import org.eclipse.rse.internal.ui.actions.SystemMoveUpConnectionAction;
@ -92,6 +95,8 @@ public class SystemViewConnectionAdapter
private SystemClearAllPasswordsAction clearPasswordAction = null; private SystemClearAllPasswordsAction clearPasswordAction = null;
private SystemCopyConnectionAction copyAction = null; private SystemCopyConnectionAction copyAction = null;
private SystemMoveConnectionAction moveAction = null; private SystemMoveConnectionAction moveAction = null;
private SystemExportConnectionAction exportAction = null;
private SystemImportConnectionAction importAction = null;
// yantzi: artemis 6.0, add work offline support // yantzi: artemis 6.0, add work offline support
private SystemWorkOfflineAction offlineAction = null; private SystemWorkOfflineAction offlineAction = null;
@ -149,6 +154,8 @@ public class SystemViewConnectionAdapter
menu.add(menuGroup, moveAction); menu.add(menuGroup, moveAction);
menu.add(menuGroup, upAction); menu.add(menuGroup, upAction);
menu.add(menuGroup, downAction); menu.add(menuGroup, downAction);
menu.add(menuGroup, exportAction);
menu.add(menuGroup, importAction);
// MJB: RE defect 40854 // MJB: RE defect 40854
addConnectOrDisconnectAction(menu, menuGroup, selection); addConnectOrDisconnectAction(menu, menuGroup, selection);
@ -203,7 +210,8 @@ public class SystemViewConnectionAdapter
offlineAction = new SystemWorkOfflineAction(null); offlineAction = new SystemWorkOfflineAction(null);
connectAction = new SystemConnectAllSubSystemsAction(null); connectAction = new SystemConnectAllSubSystemsAction(null);
clearPasswordAction = new SystemClearAllPasswordsAction(null); clearPasswordAction = new SystemClearAllPasswordsAction(null);
exportAction = new SystemExportConnectionAction();
importAction = new SystemImportConnectionAction();
actionsCreated = true; actionsCreated = true;
} }

View file

@ -30,6 +30,7 @@
* David McKnight (IBM) - [187711] Link with Editor handled by extension * David McKnight (IBM) - [187711] Link with Editor handled by extension
* David Dykstal (IBM) - [226728] NPE during init with clean workspace * David Dykstal (IBM) - [226728] NPE during init with clean workspace
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.ui.view; package org.eclipse.rse.internal.ui.view;
@ -82,8 +83,10 @@ import org.eclipse.rse.core.model.ISystemViewInputProvider;
import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
import org.eclipse.rse.internal.core.RSEInitJob; import org.eclipse.rse.internal.core.RSEInitJob;
import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.internal.ui.actions.SystemCascadingPreferencesAction; import org.eclipse.rse.internal.ui.actions.SystemCascadingPreferencesAction;
import org.eclipse.rse.internal.ui.actions.SystemCollapseAllAction; import org.eclipse.rse.internal.ui.actions.SystemCollapseAllAction;
import org.eclipse.rse.internal.ui.actions.SystemImportConnectionAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceQualifyConnectionNamesAction; import org.eclipse.rse.internal.ui.actions.SystemPreferenceQualifyConnectionNamesAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceRestoreStateAction; import org.eclipse.rse.internal.ui.actions.SystemPreferenceRestoreStateAction;
import org.eclipse.rse.internal.ui.actions.SystemPreferenceShowFilterPoolsAction; import org.eclipse.rse.internal.ui.actions.SystemPreferenceShowFilterPoolsAction;
@ -649,8 +652,12 @@ public class SystemViewPart
boolean fromPopup = false; boolean fromPopup = false;
boolean wantIcon = false; boolean wantIcon = false;
SystemNewConnectionAction newConnectionAction = new SystemNewConnectionAction(shell, fromPopup, wantIcon, sp); SystemNewConnectionAction newConnectionAction = new SystemNewConnectionAction(shell, fromPopup, wantIcon, sp);
SystemImportConnectionAction importConnectionAction = new SystemImportConnectionAction();
importConnectionAction.setShell(shell);
importConnectionAction.setText(SystemResources.RESID_IMPORT_CONNECTION_LABEL_LONG);
SystemWorkWithProfilesAction wwProfilesAction = new SystemWorkWithProfilesAction(shell); SystemWorkWithProfilesAction wwProfilesAction = new SystemWorkWithProfilesAction(shell);
menuMgr.add(newConnectionAction); menuMgr.add(newConnectionAction);
menuMgr.add(importConnectionAction);
menuMgr.add(new Separator()); menuMgr.add(new Separator());
menuMgr.add(wwProfilesAction); menuMgr.add(wwProfilesAction);
menuMgr.add(new Separator()); menuMgr.add(new Separator());