diff options
author | rescobar | 2010-07-20 20:52:40 +0000 |
---|---|---|
committer | rescobar | 2010-07-20 20:52:40 +0000 |
commit | a88b295f5a066c21fce3aefc406d1e922ca44733 (patch) | |
tree | 2df201f4b2513b0ef1c521d0144db43580cb4aac /plugins/org.eclipse.osee.framework.ui.service.control | |
parent | 9dd043fbb2a826276a59d95ae1b0ddc5df14b21c (diff) | |
download | org.eclipse.osee-a88b295f5a066c21fce3aefc406d1e922ca44733.tar.gz org.eclipse.osee-a88b295f5a066c21fce3aefc406d1e922ca44733.tar.xz org.eclipse.osee-a88b295f5a066c21fce3aefc406d1e922ca44733.zip |
Refactored to use Displays class
Diffstat (limited to 'plugins/org.eclipse.osee.framework.ui.service.control')
7 files changed, 610 insertions, 594 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java index 1720b4c3ec1..c0f9d366fd5 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java @@ -17,27 +17,28 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osee.framework.ui.service.control.dialogs.InspectReggieDialogHelper; import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; -import org.eclipse.swt.widgets.Display; +import org.eclipse.osee.framework.ui.swt.Displays; /** * @author Roberto E. Escobar */ public class InspectLookUpServerAction implements IDoubleClickListener { - private ManagerMain mainWindow; + private final ManagerMain mainWindow; - public InspectLookUpServerAction(ManagerMain mainWindow) { - super(); - this.mainWindow = mainWindow; - this.mainWindow.getLookupViewer().getViewer().addDoubleClickListener(this); - } + public InspectLookUpServerAction(ManagerMain mainWindow) { + super(); + this.mainWindow = mainWindow; + this.mainWindow.getLookupViewer().getViewer().addDoubleClickListener(this); + } - public void doubleClick(DoubleClickEvent event) { - ISelection sel = event.getSelection(); - if (!sel.isEmpty()) { - Object object = ((StructuredSelection) sel).getFirstElement(); - if (object instanceof ServiceRegistrar) { - Display.getDefault().asyncExec(new InspectReggieDialogHelper(mainWindow, (ServiceRegistrar) object)); - } - } - } + @Override + public void doubleClick(DoubleClickEvent event) { + ISelection sel = event.getSelection(); + if (!sel.isEmpty()) { + Object object = ((StructuredSelection) sel).getFirstElement(); + if (object instanceof ServiceRegistrar) { + Displays.ensureInDisplayThread(new InspectReggieDialogHelper(mainWindow, (ServiceRegistrar) object)); + } + } + } } diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java index eea7eb0ebe0..3d2d7901162 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java @@ -15,31 +15,31 @@ import org.eclipse.osee.framework.ui.service.control.ServiceControlImage; import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain;
import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchWizard;
import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceWizardDialog;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
-import org.eclipse.swt.widgets.Display;
/**
* @author Roberto E. Escobar
*/
public class OpenLaunchWizard extends Action {
- public OpenLaunchWizard(ManagerMain mainWindow) {
- super();
- setImageDescriptor(ImageManager.getImageDescriptor(ServiceControlImage.ROCKET));
- setText("Launch A Service");
- // setToolTipText("Open the service launching wizard.");
- //TODO: Please remove next two lines upon action 4ZXCH completion.
- this.setToolTipText("Disabled until action 4ZXCH is complete.");
- this.setEnabled(false);
- }
+ public OpenLaunchWizard(ManagerMain mainWindow) {
+ super();
+ setImageDescriptor(ImageManager.getImageDescriptor(ServiceControlImage.ROCKET));
+ setText("Launch A Service");
+ // setToolTipText("Open the service launching wizard.");
+ //TODO: Please remove next two lines upon action 4ZXCH completion.
+ this.setToolTipText("Disabled until action 4ZXCH is complete.");
+ this.setEnabled(false);
+ }
- @Override
- public void run() {
- super.run();
- ServiceLaunchWizard wizard = new ServiceLaunchWizard();
- ServiceWizardDialog dialog = new ServiceWizardDialog(Display.getDefault().getActiveShell(), wizard);
- dialog.setBlockOnOpen(true);
- dialog.open();
- }
+ @Override
+ public void run() {
+ super.run();
+ ServiceLaunchWizard wizard = new ServiceLaunchWizard();
+ ServiceWizardDialog dialog = new ServiceWizardDialog(Displays.getActiveShell(), wizard);
+ dialog.setBlockOnOpen(true);
+ dialog.open();
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java index 01225a87708..a3378aaae3d 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java @@ -23,7 +23,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader;
import org.eclipse.osee.framework.ui.service.control.ControlPlugin;
import org.eclipse.osee.framework.ui.service.control.managers.ServiceTreeBuilder;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.ui.PlatformUI;
/**
@@ -31,67 +31,71 @@ import org.eclipse.ui.PlatformUI; */
public class PopulateInspectReggieDialog extends Job {
- private ServiceRegistrar reggie;
- private ServiceTreeBuilder serviceTreeBuilder;
+ private final ServiceRegistrar reggie;
+ private final ServiceTreeBuilder serviceTreeBuilder;
- public PopulateInspectReggieDialog(String title, ServiceTreeBuilder serviceTreeBuilder, ServiceRegistrar reggie) {
- super(title);
- this.serviceTreeBuilder = serviceTreeBuilder;
- this.reggie = reggie;
+ public PopulateInspectReggieDialog(String title, ServiceTreeBuilder serviceTreeBuilder, ServiceRegistrar reggie) {
+ super(title);
+ this.serviceTreeBuilder = serviceTreeBuilder;
+ this.reggie = reggie;
- }
+ }
- public static void scheduleJob(Job job) {
- job.setUser(true);
- job.setPriority(Job.SHORT);
- job.schedule();
- }
+ public static void scheduleJob(Job job) {
+ job.setUser(true);
+ job.setPriority(Job.SHORT);
+ job.schedule();
+ }
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- IStatus status = Status.CANCEL_STATUS;
- ClassLoader loader = this.getThread().getContextClassLoader();
- try {
- this.getThread().setContextClassLoader(ExportClassLoader.getInstance());
- ServiceMatches serviceMatches = reggie.lookup(new ServiceTemplate(null, null, null), Integer.MAX_VALUE);
- final ServiceItem[] serviceItemArray = serviceMatches.items;
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- for (ServiceItem item : serviceItemArray) {
- serviceTreeBuilder.serviceAdded(item);
- }
- }
- });
- status = Status.OK_STATUS;
- } catch (RemoteException ex) {
- try {
- displayMessage("Reggie Lookup Error", String.format("Error searching for services in [%s:%s] reggie.\n%s",
- reggie.getLocator().getHost(), reggie.getLocator().getPort(), ControlPlugin.getStackMessages(ex)));
- } catch (RemoteException ex1) {
- displayMessage("Reggie Lookup Error", String.format("Unable to access selected the selected reggie.\n%s",
- ControlPlugin.getStackMessages(ex)));
- }
- } finally {
- this.getThread().setContextClassLoader(loader);
- }
- return status;
- }
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IStatus status = Status.CANCEL_STATUS;
+ ClassLoader loader = this.getThread().getContextClassLoader();
+ try {
+ this.getThread().setContextClassLoader(ExportClassLoader.getInstance());
+ ServiceMatches serviceMatches = reggie.lookup(new ServiceTemplate(null, null, null), Integer.MAX_VALUE);
+ final ServiceItem[] serviceItemArray = serviceMatches.items;
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ for (ServiceItem item : serviceItemArray) {
+ serviceTreeBuilder.serviceAdded(item);
+ }
+ }
+ });
+ status = Status.OK_STATUS;
+ } catch (RemoteException ex) {
+ try {
+ displayMessage("Reggie Lookup Error", String.format("Error searching for services in [%s:%s] reggie.\n%s",
+ reggie.getLocator().getHost(), reggie.getLocator().getPort(), ControlPlugin.getStackMessages(ex)));
+ } catch (RemoteException ex1) {
+ displayMessage(
+ "Reggie Lookup Error",
+ String.format("Unable to access selected the selected reggie.\n%s",
+ ControlPlugin.getStackMessages(ex)));
+ }
+ } finally {
+ this.getThread().setContextClassLoader(loader);
+ }
+ return status;
+ }
- private void displayMessage(final String title, final String message) {
- displayMessage(title, message, true);
- }
+ private void displayMessage(final String title, final String message) {
+ displayMessage(title, message, true);
+ }
- private void displayMessage(final String title, final String message, final boolean isError) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- if (isError) {
- MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message);
- } else {
- MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title,
- message);
- }
- }
- });
- }
+ private void displayMessage(final String title, final String message, final boolean isError) {
+ Displays.pendInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ if (isError) {
+ MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message);
+ } else {
+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title,
+ message);
+ }
+ }
+ });
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java index 59636198ed5..e310cb40f79 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java @@ -11,9 +11,9 @@ package org.eclipse.osee.framework.ui.service.control.jobs; import org.eclipse.osee.framework.ui.plugin.io.StreamToTextArea; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.framework.ui.swt.FormattedText; import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; /** @@ -21,67 +21,68 @@ import org.eclipse.ui.PlatformUI; */ public class TextDisplayHelper { - private FormattedText formattedText; - private StreamToTextArea errorGobbler; - private StreamToTextArea outputGobbler; + private final FormattedText formattedText; + private StreamToTextArea errorGobbler; + private StreamToTextArea outputGobbler; - public TextDisplayHelper(FormattedText formattedText) { - this.formattedText = formattedText; - this.errorGobbler = null; - this.outputGobbler = null; - } + public TextDisplayHelper(FormattedText formattedText) { + this.formattedText = formattedText; + this.errorGobbler = null; + this.outputGobbler = null; + } - public void updateScrollBar() { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - formattedText.getStyledText().setSelection(formattedText.getStyledText().getCharCount()); - } - }); - } + public void updateScrollBar() { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.getStyledText().setSelection(formattedText.getStyledText().getCharCount()); + } + }); + } - public void addText(final String toDisplay, final int format, final int color, final boolean underline) { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - formattedText.addText(toDisplay, format, color, underline); - } - }); - } + public void addText(final String toDisplay, final int format, final int color, final boolean underline) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.addText(toDisplay, format, color, underline); + } + }); + } - public void clear() { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - formattedText.clearTextArea(); - } - }); - } + public void clear() { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.clearTextArea(); + } + }); + } - public FormattedText getFormattedText() { - return formattedText; - } + public FormattedText getFormattedText() { + return formattedText; + } - public void startProcessHandling(Process process) { - disposeProcessHandling(); - errorGobbler = new StreamToTextArea(process.getErrorStream(), "\t\terr", getFormattedText()); - errorGobbler.setName("ServiceErrorHandler"); - errorGobbler.typeColor(SWT.COLOR_RED); - outputGobbler = new StreamToTextArea(process.getInputStream(), "\t\tout", getFormattedText()); - outputGobbler.setName("ServiceOutputHandler"); - outputGobbler.typeColor(SWT.COLOR_DARK_BLUE); + public void startProcessHandling(Process process) { + disposeProcessHandling(); + errorGobbler = new StreamToTextArea(process.getErrorStream(), "\t\terr", getFormattedText()); + errorGobbler.setName("ServiceErrorHandler"); + errorGobbler.typeColor(SWT.COLOR_RED); + outputGobbler = new StreamToTextArea(process.getInputStream(), "\t\tout", getFormattedText()); + outputGobbler.setName("ServiceOutputHandler"); + outputGobbler.typeColor(SWT.COLOR_DARK_BLUE); - errorGobbler.start(); - outputGobbler.start(); - } + errorGobbler.start(); + outputGobbler.start(); + } - public void disposeProcessHandling() { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (errorGobbler != null) { - errorGobbler.setStopped(true); - } - if (outputGobbler != null) { - outputGobbler.setStopped(true); - } - } - }); - } + public void disposeProcessHandling() { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + if (errorGobbler != null) { + errorGobbler.setStopped(true); + } + if (outputGobbler != null) { + outputGobbler.setStopped(true); + } + } + }); + } } diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java index 105db5a7b32..e5c7947c8fd 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java @@ -18,7 +18,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.util.Map; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -29,13 +28,12 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osee.framework.ui.service.control.ControlPlugin; import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; import org.eclipse.osee.framework.ui.service.control.wizards.launcher.pages.UploadPage.LabelEnum; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.osgi.framework.Bundle; - import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.SftpException; @@ -44,191 +42,200 @@ import com.jcraft.jsch.SftpException; */ public class UploadRemoteFileJob extends Job { - private ServiceLaunchingInformation serviceInfo; - private TextDisplayHelper display; - private ProgressBar progress; - private Map<LabelEnum, Text> dataMap; - private boolean isUploadDirCreationAllowed; - - public UploadRemoteFileJob(String name, ServiceLaunchingInformation serviceInfo, TextDisplayHelper display, ProgressBar progress, Map<LabelEnum, Text> dataMap) { - super(name); - if (serviceInfo == null) throw new IllegalArgumentException("serviceInfo can not be null"); - if (display == null) throw new IllegalArgumentException("display can not be null"); - if (progress == null) throw new IllegalArgumentException("progress can not be null"); - this.serviceInfo = serviceInfo; - this.display = display; - this.progress = progress; - this.dataMap = dataMap; - this.isUploadDirCreationAllowed = false; - progress.setSelection(0); - progress.setMaximum(0); - progress.setMaximum(5); - } - - private void incrementProgress(final int increment) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - int position = progress.getSelection(); - progress.setSelection(position + increment); - } - }); - } - - private void displayInitMessage(File zipLocation) { - display.clear(); - display.addText("\t\t ----------- Unzip -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); - display.addText("\tFrom Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); - display.addText(String.format("\t%s\n", zipLocation.getAbsolutePath()), SWT.NORMAL, SWT.COLOR_BLACK, false); - display.addText("\tTo Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); - display.addText(String.format("\t%s://%s\n", serviceInfo.getSelectedHost(), serviceInfo.getUnzipLocation()), - SWT.NORMAL, SWT.COLOR_BLACK, false); - } - - private ChannelSftp getScpConnection() throws Exception { - display.addText("\n\tStarting SCP...", SWT.NORMAL, SWT.COLOR_BLACK, false); - ChannelSftp sftp = this.serviceInfo.getSSHConnection().getScpConnection(); - incrementProgress(1); - return sftp; - } - - private void createRemotePathOrCdIntoIt(IProgressMonitor monitor, ChannelSftp sftp) throws Exception { - if (monitor.isCanceled() != true) { - try { - sftp.cd(serviceInfo.getUnzipLocation()); - } catch (SftpException ex1) { - this.isUploadDirCreationAllowed = false; - Display.getDefault().syncExec(new Runnable() { - public void run() { - Shell shell = Display.getDefault().getActiveShell(); - isUploadDirCreationAllowed = - MessageDialog.openQuestion(shell, "Scp", - "Unable to find remote path. Would you like to create it?"); - } - }); - - if (isUploadDirCreationAllowed == true) { - try { - sftp.mkdir(serviceInfo.getUnzipLocation()); - } catch (SftpException ex2) { - throw new Exception("Unable to create remote path."); - } - } else { - throw new Exception("Unable to find remote path - user selected not to create it."); - } - - } finally { - incrementProgress(1); - } - } - } - - private void uploadFile(IProgressMonitor monitor, ChannelSftp sftp, File fileToUpload) throws Exception { - if (monitor.isCanceled() != true) { - display.addText(String.format("\n\tUploading [%s]", fileToUpload.getAbsolutePath()), SWT.NORMAL, - SWT.COLOR_BLACK, false); - InputStream input = null; - OutputStream output = null; - try { - input = new FileInputStream(fileToUpload); - output = sftp.put(fileToUpload.getName()); - byte[] buffer = new byte[1024]; - int count = -1; - while ((count = input.read(buffer)) != -1) { - output.write(buffer, 0, count); - } - display.addText(String.format("\n\tTransferred [%s] bytes", fileToUpload.length()), SWT.NORMAL, - SWT.COLOR_BLACK, false); - } catch (SftpException ex1) { - throw new Exception("Error uploading file."); - } finally { - incrementProgress(1); - if (input != null) { - input.close(); - } - if (output != null) { - output.close(); - } - } - } - } - - private void unzipRemoteFiles(IProgressMonitor monitor) throws Exception { - if (monitor.isCanceled() != true) { - String toExec = - String.format("cd %s\nunzip -o %s", serviceInfo.getUnzipLocation(), - serviceInfo.getServiceItem().getZipName()); - - display.addText("\n\tUnzip Cmd: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); - display.addText("\t" + toExec.split("\n")[1] + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); - - String output = this.serviceInfo.getSSHConnection().executeCommandList(toExec.split("\n")); - display.addText("\n\t" + output + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); - incrementProgress(1); - } - } - - public File getFile(Bundle bundle, String path) throws FileNotFoundException, IOException { - URL url = bundle.getEntry(path); - if (url == null) { - throw new FileNotFoundException("Could not locate the file " + path); - } - try { - url = FileLocator.toFileURL(url); - File file = new File(url.getFile()); - return file; - } catch (Throwable e) { - throw new IOException("Invalid URL format for the URL " + url.toString(), e); - } - } - - @Override - public IStatus run(IProgressMonitor monitor) { - IStatus toReturn = Status.OK_STATUS; - ChannelSftp sftp = null; - try { - Display.getDefault().syncExec(new Runnable() { - public void run() { - serviceInfo.setUnzipLocation(dataMap.get(LabelEnum.Host_Upload_Location).getText()); - } - }); - Bundle bundle = Platform.getBundle(serviceInfo.getServiceItem().getPlugin()); - File zipLocation = getFile(bundle, serviceInfo.getServiceItem().getZipName()); - - displayInitMessage(zipLocation); - - sftp = getScpConnection(); - - createRemotePathOrCdIntoIt(monitor, sftp); - - uploadFile(monitor, sftp, zipLocation); - - unzipRemoteFiles(monitor); - - } catch (Exception ex) { - display.addText(String.format("\n\t%s\n\n", ex.getLocalizedMessage()), SWT.NORMAL, SWT.COLOR_RED, false); - toReturn = new Status(Status.ERROR, ControlPlugin.PLUGIN_PREFERENCE_SCOPE, "Error during upload.", ex); - } finally { - incrementProgress(5); - if (sftp != null) { - sftp.exit(); - sftp.disconnect(); - } - } - - // incrementProgress(1); - // if (true != createDestinationFolder()) { - // incrementProgress(4); - // toReturn = Status.CANCEL_STATUS; - // } else { - - // if (true != toReturn.equals(Status.OK_STATUS)) { - // PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - // public void run() { - // MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Upload Error", - // "Upload of files to remote host failed."); - // } - // }); - // } - return toReturn; - } + private final ServiceLaunchingInformation serviceInfo; + private final TextDisplayHelper display; + private final ProgressBar progress; + private final Map<LabelEnum, Text> dataMap; + private boolean isUploadDirCreationAllowed; + + public UploadRemoteFileJob(String name, ServiceLaunchingInformation serviceInfo, TextDisplayHelper display, ProgressBar progress, Map<LabelEnum, Text> dataMap) { + super(name); + if (serviceInfo == null) { + throw new IllegalArgumentException("serviceInfo can not be null"); + } + if (display == null) { + throw new IllegalArgumentException("display can not be null"); + } + if (progress == null) { + throw new IllegalArgumentException("progress can not be null"); + } + this.serviceInfo = serviceInfo; + this.display = display; + this.progress = progress; + this.dataMap = dataMap; + this.isUploadDirCreationAllowed = false; + progress.setSelection(0); + progress.setMaximum(0); + progress.setMaximum(5); + } + + private void incrementProgress(final int increment) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + int position = progress.getSelection(); + progress.setSelection(position + increment); + } + }); + } + + private void displayInitMessage(File zipLocation) { + display.clear(); + display.addText("\t\t ----------- Unzip -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); + display.addText("\tFrom Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText(String.format("\t%s\n", zipLocation.getAbsolutePath()), SWT.NORMAL, SWT.COLOR_BLACK, false); + display.addText("\tTo Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText(String.format("\t%s://%s\n", serviceInfo.getSelectedHost(), serviceInfo.getUnzipLocation()), + SWT.NORMAL, SWT.COLOR_BLACK, false); + } + + private ChannelSftp getScpConnection() throws Exception { + display.addText("\n\tStarting SCP...", SWT.NORMAL, SWT.COLOR_BLACK, false); + ChannelSftp sftp = this.serviceInfo.getSSHConnection().getScpConnection(); + incrementProgress(1); + return sftp; + } + + private void createRemotePathOrCdIntoIt(IProgressMonitor monitor, ChannelSftp sftp) throws Exception { + if (monitor.isCanceled() != true) { + try { + sftp.cd(serviceInfo.getUnzipLocation()); + } catch (SftpException ex1) { + this.isUploadDirCreationAllowed = false; + Displays.pendInDisplayThread(new Runnable() { + @Override + public void run() { + Shell shell = Displays.getActiveShell(); + isUploadDirCreationAllowed = + MessageDialog.openQuestion(shell, "Scp", + "Unable to find remote path. Would you like to create it?"); + } + }); + + if (isUploadDirCreationAllowed == true) { + try { + sftp.mkdir(serviceInfo.getUnzipLocation()); + } catch (SftpException ex2) { + throw new Exception("Unable to create remote path."); + } + } else { + throw new Exception("Unable to find remote path - user selected not to create it."); + } + + } finally { + incrementProgress(1); + } + } + } + + private void uploadFile(IProgressMonitor monitor, ChannelSftp sftp, File fileToUpload) throws Exception { + if (monitor.isCanceled() != true) { + display.addText(String.format("\n\tUploading [%s]", fileToUpload.getAbsolutePath()), SWT.NORMAL, + SWT.COLOR_BLACK, false); + InputStream input = null; + OutputStream output = null; + try { + input = new FileInputStream(fileToUpload); + output = sftp.put(fileToUpload.getName()); + byte[] buffer = new byte[1024]; + int count = -1; + while ((count = input.read(buffer)) != -1) { + output.write(buffer, 0, count); + } + display.addText(String.format("\n\tTransferred [%s] bytes", fileToUpload.length()), SWT.NORMAL, + SWT.COLOR_BLACK, false); + } catch (SftpException ex1) { + throw new Exception("Error uploading file."); + } finally { + incrementProgress(1); + if (input != null) { + input.close(); + } + if (output != null) { + output.close(); + } + } + } + } + + private void unzipRemoteFiles(IProgressMonitor monitor) throws Exception { + if (monitor.isCanceled() != true) { + String toExec = + String.format("cd %s\nunzip -o %s", serviceInfo.getUnzipLocation(), + serviceInfo.getServiceItem().getZipName()); + + display.addText("\n\tUnzip Cmd: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + toExec.split("\n")[1] + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + + String output = this.serviceInfo.getSSHConnection().executeCommandList(toExec.split("\n")); + display.addText("\n\t" + output + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + incrementProgress(1); + } + } + + public File getFile(Bundle bundle, String path) throws FileNotFoundException, IOException { + URL url = bundle.getEntry(path); + if (url == null) { + throw new FileNotFoundException("Could not locate the file " + path); + } + try { + url = FileLocator.toFileURL(url); + File file = new File(url.getFile()); + return file; + } catch (Throwable e) { + throw new IOException("Invalid URL format for the URL " + url.toString(), e); + } + } + + @Override + public IStatus run(IProgressMonitor monitor) { + IStatus toReturn = Status.OK_STATUS; + ChannelSftp sftp = null; + try { + Displays.pendInDisplayThread(new Runnable() { + @Override + public void run() { + serviceInfo.setUnzipLocation(dataMap.get(LabelEnum.Host_Upload_Location).getText()); + } + }); + Bundle bundle = Platform.getBundle(serviceInfo.getServiceItem().getPlugin()); + File zipLocation = getFile(bundle, serviceInfo.getServiceItem().getZipName()); + + displayInitMessage(zipLocation); + + sftp = getScpConnection(); + + createRemotePathOrCdIntoIt(monitor, sftp); + + uploadFile(monitor, sftp, zipLocation); + + unzipRemoteFiles(monitor); + + } catch (Exception ex) { + display.addText(String.format("\n\t%s\n\n", ex.getLocalizedMessage()), SWT.NORMAL, SWT.COLOR_RED, false); + toReturn = new Status(Status.ERROR, ControlPlugin.PLUGIN_PREFERENCE_SCOPE, "Error during upload.", ex); + } finally { + incrementProgress(5); + if (sftp != null) { + sftp.exit(); + sftp.disconnect(); + } + } + + // incrementProgress(1); + // if (true != createDestinationFolder()) { + // incrementProgress(4); + // toReturn = Status.CANCEL_STATUS; + // } else { + + // if (true != toReturn.equals(Status.OK_STATUS)) { + // PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + // public void run() { + // MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Upload Error", + // "Upload of files to remote host failed."); + // } + // }); + // } + return toReturn; + } } diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java index 43247b475e8..f07005ddfea 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java @@ -23,13 +23,13 @@ import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.osee.framework.ui.service.control.ServiceControlImage;
import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer;
import org.eclipse.osee.framework.ui.service.control.renderer.ReggieItemHandler;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
@@ -38,106 +38,108 @@ import org.eclipse.swt.widgets.TableItem; */
public class LookupViewer extends Composite {
- private static final Image LOOK_UP_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECTION);//ControlPlugin.getInstance().getImage("connection.gif");
- private static final Image DISCONNECTED_IMAGE = ImageManager.getImage(ServiceControlImage.DISCONNECTED);//ControlPlugin.getInstance().getImage("disconnected.gif");
-
- private StructuredViewer viewer;
- private Map<ServiceID, IRenderer> handlerMap;
-
- public LookupViewer(Composite parent, int style) {
- super(parent, style);
- createControl();
- }
-
- private void createControl() {
- this.setLayout(new GridLayout());
- this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- viewer = new TableViewer(this, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- viewer.setLabelProvider(new ListLabelProvider());
- viewer.setContentProvider(new ArrayContentProvider());
- viewer.setSorter(new ViewerSorter());
- viewer.setInput(new String[0]);
- }
-
- public void refresh() {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- viewer.refresh();
- }
- });
- }
-
- public void setSelection(final String serviceId) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- Table table = ((TableViewer) viewer).getTable();
- TableItem[] items = table.getItems();
- for (TableItem item : items) {
- Object object = item.getData();
- if (object instanceof ServiceRegistrar) {
- if (((ServiceRegistrar) object).getServiceID().toString().equals(serviceId)) {
- table.setSelection(new TableItem[] {item});
- return;
- }
- }
- }
- }
- });
- }
-
- public StructuredViewer getViewer() {
- return viewer;
- }
-
- public void setInput(Collection<?> input) {
- viewer.setInput(input);
- }
-
- public void setRendererMap(Map<ServiceID, IRenderer> map) {
- this.handlerMap = map;
- }
-
- public IRenderer getRenderer(ServiceID serviceId) {
- if (handlerMap != null) {
- return handlerMap.get(serviceId);
- } else {
- return null;
- }
- }
-
- private class ListLabelProvider extends LabelProvider {
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof ServiceRegistrar) {
- if (ReggieItemHandler.isAllowed((ServiceRegistrar) element)) {
- return LOOK_UP_IMAGE;
- } else {
- return DISCONNECTED_IMAGE;
- }
- }
- return null;
- }
-
- @Override
- public String getText(Object element) {
- if (element instanceof ServiceRegistrar) {
- ServiceRegistrar reggie = (ServiceRegistrar) element;
- try {
- return " Jini Lookup: " + reggie.getLocator().getHost() + " : " + reggie.getLocator().getPort();
- } catch (RemoteException ex) {
- ex.printStackTrace();
- return "Jini Lookup: " + "UNABLE TO LOCATE";
- }
- }
- return "";
- }
- }
-
- @Override
- public void dispose() {
- viewer.getControl().dispose();
- }
+ private static final Image LOOK_UP_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECTION);//ControlPlugin.getInstance().getImage("connection.gif");
+ private static final Image DISCONNECTED_IMAGE = ImageManager.getImage(ServiceControlImage.DISCONNECTED);//ControlPlugin.getInstance().getImage("disconnected.gif");
+
+ private StructuredViewer viewer;
+ private Map<ServiceID, IRenderer> handlerMap;
+
+ public LookupViewer(Composite parent, int style) {
+ super(parent, style);
+ createControl();
+ }
+
+ private void createControl() {
+ this.setLayout(new GridLayout());
+ this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ viewer = new TableViewer(this, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.setLabelProvider(new ListLabelProvider());
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setSorter(new ViewerSorter());
+ viewer.setInput(new String[0]);
+ }
+
+ public void refresh() {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ viewer.refresh();
+ }
+ });
+ }
+
+ public void setSelection(final String serviceId) {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ Table table = ((TableViewer) viewer).getTable();
+ TableItem[] items = table.getItems();
+ for (TableItem item : items) {
+ Object object = item.getData();
+ if (object instanceof ServiceRegistrar) {
+ if (((ServiceRegistrar) object).getServiceID().toString().equals(serviceId)) {
+ table.setSelection(new TableItem[] {item});
+ return;
+ }
+ }
+ }
+ }
+ });
+ }
+
+ public StructuredViewer getViewer() {
+ return viewer;
+ }
+
+ public void setInput(Collection<?> input) {
+ viewer.setInput(input);
+ }
+
+ public void setRendererMap(Map<ServiceID, IRenderer> map) {
+ this.handlerMap = map;
+ }
+
+ public IRenderer getRenderer(ServiceID serviceId) {
+ if (handlerMap != null) {
+ return handlerMap.get(serviceId);
+ } else {
+ return null;
+ }
+ }
+
+ private class ListLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof ServiceRegistrar) {
+ if (ReggieItemHandler.isAllowed((ServiceRegistrar) element)) {
+ return LOOK_UP_IMAGE;
+ } else {
+ return DISCONNECTED_IMAGE;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof ServiceRegistrar) {
+ ServiceRegistrar reggie = (ServiceRegistrar) element;
+ try {
+ return " Jini Lookup: " + reggie.getLocator().getHost() + " : " + reggie.getLocator().getPort();
+ } catch (RemoteException ex) {
+ ex.printStackTrace();
+ return "Jini Lookup: " + "UNABLE TO LOCATE";
+ }
+ }
+ return "";
+ }
+ }
+
+ @Override
+ public void dispose() {
+ viewer.getControl().dispose();
+ }
}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java index a13ddb49df8..2cc3bd0a39e 100644 --- a/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java +++ b/plugins/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java @@ -30,13 +30,13 @@ import org.eclipse.osee.framework.ui.service.control.data.CategoryParent; import org.eclipse.osee.framework.ui.service.control.data.GroupParent;
import org.eclipse.osee.framework.ui.service.control.data.ServiceNode;
import org.eclipse.osee.framework.ui.service.control.managers.ConnectionManager;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
@@ -45,158 +45,159 @@ import org.eclipse.ui.PlatformUI; */
public class ServicesViewer extends Composite {
- private static final Image CONFIG_IMAGE = ImageManager.getImage(ServiceControlImage.CONFIG);
- private static final Image FOLDER_IMAGE =
- PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
- private static final Image GROUP_IMAGE = ImageManager.getImage(ServiceControlImage.GROUP);
- private static final Image CONNECT_FOLDER_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECT_FOLDER);
- private static final Image CONNECTED_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECTED_PLUG);
-
- private StructuredViewer viewer;
- private final Map<Class<?>, Image> serviceIconMap;
-
- public ServicesViewer(Composite parent, int style) {
- super(parent, style);
- create();
- serviceIconMap = new HashMap<Class<?>, Image>();
- }
-
- private void create() {
- this.setLayout(new GridLayout());
- this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createTreeArea(this);
- }
-
- private void createTreeArea(Composite parent) {
- viewer = new TreeViewer(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- viewer.setContentProvider(new TreeContentProvider());
- viewer.setLabelProvider(new TreeLabelProvider());
- viewer.setSorter(new ViewerSorter());
- viewer.setInput(new ArrayList<String>());
- viewer.getControl().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
- }
-
- private class TreeLabelProvider extends LabelProvider {
-
- @Override
- public Image getImage(Object obj) {
- Image toReturn = null;
- if (obj instanceof GroupParent) {
- toReturn = GROUP_IMAGE;
- } else if (obj instanceof CategoryParent) {
- toReturn = FOLDER_IMAGE;
- CategoryParent categoryParent = (CategoryParent) obj;
- if (categoryParent.hasChildren()) {
- Object child = categoryParent.getChildren()[0];
- if (child instanceof ServiceNode) {
- ServiceNode serviceNode = (ServiceNode) child;
- if (ConnectionManager.getInstance().isAllowedConnectionType(serviceNode.getServiceItem())) {
- toReturn = CONNECT_FOLDER_IMAGE;
- }
- }
- }
- } else if (obj instanceof ServiceNode) {
- ServiceNode node = (ServiceNode) obj;
- if (node.isConnected()) {
- toReturn = CONNECTED_IMAGE;
- } else {
- toReturn = CONFIG_IMAGE;
- ServiceItem serviceItem = node.getServiceItem();
- for (Class<?> classType : serviceIconMap.keySet()) {
- if (classType.isInstance(serviceItem.service)) {
- Image image = serviceIconMap.get(classType);
- if (image != null) {
- toReturn = image;
- }
- break;
- }
- }
- }
- }
- return toReturn;
- }
-
- @Override
- public String getText(Object obj) {
- return obj.toString();
- }
- }
-
- private class TreeContentProvider implements ITreeContentProvider {
-
- public void dispose() {
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement != null && parentElement instanceof TreeParent) {
- TreeParent parent = (TreeParent) parentElement;
- if (parent.hasChildren()) {
- return parent.getChildren();
- }
- }
- return new Object[0];
- }
-
- public Object[] getElements(Object inputElement) {
- if (inputElement != null && inputElement instanceof Collection<?>) {
- Collection<?> elementArray = (Collection<?>) inputElement;
- return elementArray.toArray();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- if (element != null && element instanceof TreeObject) {
- TreeObject child = (TreeObject) element;
- return child.getParent();
- }
- return new Object();
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof TreeParent) {
- TreeParent parent = (TreeParent) element;
- return parent.hasChildren();
- }
- return false;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- }
-
- @Override
- public boolean setFocus() {
- return this.viewer.getControl().setFocus();
- }
-
- public StructuredViewer getViewer() {
- return viewer;
- }
-
- public void setInput(List<TreeParent> input) {
- viewer.setInput(input);
- }
-
- public void refresh() {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (viewer != null && !viewer.getControl().isDisposed()) {
- viewer.refresh();
- }
- }
- });
- }
-
- @Override
- public void dispose() {
- viewer.getControl().dispose();
- super.dispose();
- }
-
- public void registerImage(Class<?> serviceType, ImageDescriptor icon) {
- serviceIconMap.put(serviceType, icon.createImage());
- }
+ private static final Image CONFIG_IMAGE = ImageManager.getImage(ServiceControlImage.CONFIG);
+ private static final Image FOLDER_IMAGE = PlatformUI.getWorkbench().getSharedImages().getImage(
+ ISharedImages.IMG_OBJ_FOLDER);
+ private static final Image GROUP_IMAGE = ImageManager.getImage(ServiceControlImage.GROUP);
+ private static final Image CONNECT_FOLDER_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECT_FOLDER);
+ private static final Image CONNECTED_IMAGE = ImageManager.getImage(ServiceControlImage.CONNECTED_PLUG);
+
+ private StructuredViewer viewer;
+ private final Map<Class<?>, Image> serviceIconMap;
+
+ public ServicesViewer(Composite parent, int style) {
+ super(parent, style);
+ create();
+ serviceIconMap = new HashMap<Class<?>, Image>();
+ }
+
+ private void create() {
+ this.setLayout(new GridLayout());
+ this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createTreeArea(this);
+ }
+
+ private void createTreeArea(Composite parent) {
+ viewer = new TreeViewer(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.setContentProvider(new TreeContentProvider());
+ viewer.setLabelProvider(new TreeLabelProvider());
+ viewer.setSorter(new ViewerSorter());
+ viewer.setInput(new ArrayList<String>());
+ viewer.getControl().setBackground(Displays.getSystemColor(SWT.COLOR_WHITE));
+ }
+
+ private class TreeLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object obj) {
+ Image toReturn = null;
+ if (obj instanceof GroupParent) {
+ toReturn = GROUP_IMAGE;
+ } else if (obj instanceof CategoryParent) {
+ toReturn = FOLDER_IMAGE;
+ CategoryParent categoryParent = (CategoryParent) obj;
+ if (categoryParent.hasChildren()) {
+ Object child = categoryParent.getChildren()[0];
+ if (child instanceof ServiceNode) {
+ ServiceNode serviceNode = (ServiceNode) child;
+ if (ConnectionManager.getInstance().isAllowedConnectionType(serviceNode.getServiceItem())) {
+ toReturn = CONNECT_FOLDER_IMAGE;
+ }
+ }
+ }
+ } else if (obj instanceof ServiceNode) {
+ ServiceNode node = (ServiceNode) obj;
+ if (node.isConnected()) {
+ toReturn = CONNECTED_IMAGE;
+ } else {
+ toReturn = CONFIG_IMAGE;
+ ServiceItem serviceItem = node.getServiceItem();
+ for (Class<?> classType : serviceIconMap.keySet()) {
+ if (classType.isInstance(serviceItem.service)) {
+ Image image = serviceIconMap.get(classType);
+ if (image != null) {
+ toReturn = image;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ @Override
+ public String getText(Object obj) {
+ return obj.toString();
+ }
+ }
+
+ private class TreeContentProvider implements ITreeContentProvider {
+
+ public void dispose() {
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement != null && parentElement instanceof TreeParent) {
+ TreeParent parent = (TreeParent) parentElement;
+ if (parent.hasChildren()) {
+ return parent.getChildren();
+ }
+ }
+ return new Object[0];
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement != null && inputElement instanceof Collection<?>) {
+ Collection<?> elementArray = (Collection<?>) inputElement;
+ return elementArray.toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if (element != null && element instanceof TreeObject) {
+ TreeObject child = (TreeObject) element;
+ return child.getParent();
+ }
+ return new Object();
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof TreeParent) {
+ TreeParent parent = (TreeParent) element;
+ return parent.hasChildren();
+ }
+ return false;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ @Override
+ public boolean setFocus() {
+ return this.viewer.getControl().setFocus();
+ }
+
+ public StructuredViewer getViewer() {
+ return viewer;
+ }
+
+ public void setInput(List<TreeParent> input) {
+ viewer.setInput(input);
+ }
+
+ public void refresh() {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ if (viewer != null && !viewer.getControl().isDisposed()) {
+ viewer.refresh();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void dispose() {
+ viewer.getControl().dispose();
+ super.dispose();
+ }
+
+ public void registerImage(Class<?> serviceType, ImageDescriptor icon) {
+ serviceIconMap.put(serviceType, icon.createImage());
+ }
}
|