Author: snjeza
Date: 2011-10-16 17:09:55 -0400 (Sun, 16 Oct 2011)
New Revision: 35691
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeViewerDialog.java
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/actions/DownloadRuntimeAction.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
Log:
JBIDE-9368 Dashboard(s) for easy news aggregation, twitter and easy additional/3rd party
plugin installation and project template/creation
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/actions/DownloadRuntimeAction.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/actions/DownloadRuntimeAction.java 2011-10-16
20:40:50 UTC (rev 35690)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/actions/DownloadRuntimeAction.java 2011-10-16
21:09:55 UTC (rev 35691)
@@ -1,35 +1,29 @@
+/*************************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, 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:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
package org.jboss.tools.runtime.ui.actions;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Set;
-
import org.eclipse.core.runtime.Assert;
-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.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
-import org.jboss.tools.runtime.core.JBossRuntimeLocator;
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.DownloadRuntime;
-import org.jboss.tools.runtime.core.model.IRuntimeDetector;
-import org.jboss.tools.runtime.core.model.RuntimePath;
-import org.jboss.tools.runtime.core.model.ServerDefinition;
-import org.jboss.tools.runtime.ui.RuntimeUIActivator;
+import org.jboss.tools.runtime.ui.dialogs.DownloadRuntimeDialog;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class DownloadRuntimeAction extends Action {
private String runtimeId;
@@ -59,113 +53,17 @@
setRuntimeId(runtimeId);
}
- private void downloadRuntime(final DownloadRuntime runtime) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- DirectoryDialog dialog = new DirectoryDialog(shell);
- dialog.setMessage("Select installation directory.");
- //dialog.setFilterPath("");
- final String selectedDirectory = dialog.open();
- if (selectedDirectory != null) {
- Job job = new Job("Download '" + runtime.getName() + "'
...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- return downloadAndInstall(runtime, selectedDirectory, monitor);
- }
- };
- job.setUser(true);
- job.schedule();
- }
- }
-
- private IStatus downloadAndInstall(DownloadRuntime runtime,
- String selectedDirectory, IProgressMonitor monitor) {
- FileInputStream in = null;
- OutputStream out = null;
- try {
- File file = File.createTempFile("JBossRuntime", "tmp");
- file.deleteOnExit();
- out = new BufferedOutputStream(
- new FileOutputStream(file));
- URL url = new URL(runtime.getUrl());
- String name = url.getPath();
- int slashIdx = name.lastIndexOf('/');
- if (slashIdx >= 0)
- name = name.substring(slashIdx + 1);
-
- IStatus result = ECFExamplesTransport.getInstance().download(name,
- url.toExternalForm(), out, monitor);
- out.flush();
- out.close();
- File directory = new File(selectedDirectory);
- directory.mkdirs();
- if (!directory.isDirectory()) {
- RuntimeCoreActivator.getDefault().getLog().log(result);
- // FIXME
- return Status.CANCEL_STATUS;
- }
- ProjectExamplesActivator.extractZipFile(file, directory, monitor);
- if (!result.isOK()) {
- RuntimeCoreActivator.getDefault().getLog().log(result);
- // FIXME
- return Status.CANCEL_STATUS;
- }
- createRuntimes(selectedDirectory, monitor);
- } catch (IOException e) {
- RuntimeCoreActivator.log(e);
- // FIXME
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- return Status.OK_STATUS;
- }
-
- private static void createRuntimes(String directory, IProgressMonitor monitor) {
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
- .getRuntimePaths();
- RuntimePath newPath = new RuntimePath(directory);
- runtimePaths.add(newPath);
- for (RuntimePath runtimePath : runtimePaths) {
- List<ServerDefinition> serverDefinitions = locator
- .searchForRuntimes(runtimePath.getPath(),
- monitor);
- runtimePath.getServerDefinitions().clear();
- for (ServerDefinition serverDefinition : serverDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- runtimePath.getServerDefinitions().addAll(serverDefinitions);
- }
- List<ServerDefinition> serverDefinitions = RuntimeUIActivator
- .getDefault().getServerDefinitions();
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator
- .getRuntimeDetectors();
- for (IRuntimeDetector detector : detectors) {
- if (detector.isEnabled()) {
- detector.initializeRuntimes(serverDefinitions);
- }
- }
- }
-
@Override
public void run() {
Assert.isNotNull(runtimeId);
DownloadRuntime runtime =
RuntimeCoreActivator.getDefault().getDownloadJBossRuntimes().get(runtimeId);
- Assert.isNotNull(runtime);
- downloadRuntime(runtime);
+ DownloadRuntimeDialog dialog = new DownloadRuntimeDialog(getShell(), runtime);
+ dialog.open();
}
+ private Shell getShell() {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+
+ }
+
}
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeDialog.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeDialog.java
(rev 0)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeDialog.java 2011-10-16
21:09:55 UTC (rev 35691)
@@ -0,0 +1,364 @@
+/*************************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, 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:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.runtime.ui.dialogs;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+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.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
+import org.jboss.tools.runtime.core.JBossRuntimeLocator;
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.model.DownloadRuntime;
+import org.jboss.tools.runtime.core.model.IRuntimeDetector;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.core.model.ServerDefinition;
+import org.jboss.tools.runtime.ui.RuntimeUIActivator;
+
+/**
+ * @author snjeza
+ *
+ */
+public class DownloadRuntimeDialog extends Dialog {
+
+ private static final String DELETE_ON_EXIT = "deleteOnExit";
+ private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
+ private static final String USER_HOME = "user.home";
+ private static final String DEFAULT_DIALOG_PATH = "defaultDialogPath";
+ private static final String DEFAULT_DESTINATION_PATH =
"defaultDestinationPath";
+ private IDialogSettings dialogSettings;
+ private Button deleteOnExit;
+ private Text destinationPathText;
+ private Text pathText;
+ private DownloadRuntime downloadRuntime;
+ private String delete;
+
+ public DownloadRuntimeDialog(Shell parentShell, DownloadRuntime downloadRuntime) {
+ super(parentShell);
+ setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
+ | SWT.RESIZE | getDefaultOrientation());
+ dialogSettings = RuntimeUIActivator.getDefault().getDialogSettings();
+ this.downloadRuntime = downloadRuntime;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ getShell().setText("Download Runtime '" + downloadRuntime.getName() +
"'");
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ //gd.heightHint = 200;
+ gd.widthHint = 600;
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout(1, false));
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ Composite pathComposite = new Composite(contents, SWT.NONE);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ pathComposite.setLayoutData(gd);
+ pathComposite.setLayout(new GridLayout(3, false));
+
+
+ Label pathLabel = new Label(pathComposite, SWT.NONE);
+ pathLabel.setText("Installation directory:");
+
+ pathText = new Text(pathComposite, SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ pathText.setLayoutData(gd);
+ String defaultPath = dialogSettings.get(DEFAULT_DIALOG_PATH);
+ if (defaultPath == null || defaultPath.isEmpty()) {
+ defaultPath=System.getProperty(USER_HOME);
+ }
+ pathText.setText(defaultPath);
+ pathText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+
+ Button browseButton = new Button(pathComposite, SWT.NONE);
+ browseButton.setText("Browse...");
+ browseButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Select installation directory");
+ dialog.setFilterPath(pathText.getText());
+ final String path = dialog.open();
+ if (path == null) {
+ return;
+ }
+ pathText.setText(path);
+ }
+
+ });
+
+ Label destinationLabel = new Label(pathComposite, SWT.NONE);
+ destinationLabel.setText("Destination directory:");
+
+ destinationPathText = new Text(pathComposite, SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ destinationPathText.setLayoutData(gd);
+ String destinationPath = dialogSettings.get(DEFAULT_DESTINATION_PATH);
+ if (destinationPath == null || destinationPath.isEmpty()) {
+ destinationPath=System.getProperty(JAVA_IO_TMPDIR);
+ }
+ destinationPathText.setText(destinationPath);
+
+ Button browseDestinationButton = new Button(pathComposite, SWT.NONE);
+ browseDestinationButton.setText("Browse...");
+ browseDestinationButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Select destination directory");
+ dialog.setFilterPath(destinationPathText.getText());
+ final String path = dialog.open();
+ if (path == null) {
+ return;
+ }
+ destinationPathText.setText(path);
+ }
+
+ });
+
+ destinationPathText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+
+ deleteOnExit = new Button(pathComposite, SWT.CHECK);
+ deleteOnExit.setText("Delete archive after installing");
+
+ delete = dialogSettings.get(DELETE_ON_EXIT);
+ if (delete == null) {
+ delete = "true";
+ }
+ deleteOnExit.setSelection(new Boolean(delete));
+ deleteOnExit.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ delete = new Boolean(deleteOnExit.getSelection()).toString();
+ }
+
+ });
+
+ return area;
+ }
+
+ protected void validate() {
+ getButton(IDialogConstants.OK_ID).setEnabled(true);
+ if (pathText.getText().isEmpty()) {
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+ if (destinationPathText.getText().isEmpty()) {
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ dialogSettings.put(DEFAULT_DESTINATION_PATH,
+ destinationPathText.getText());
+ dialogSettings.put(DEFAULT_DIALOG_PATH, pathText.getText());
+ dialogSettings.put(DELETE_ON_EXIT, delete);
+ String selectedDirectory = pathText.getText();
+ String destinationDirectory = destinationPathText.getText();
+ boolean del = deleteOnExit.getSelection();
+ super.okPressed();
+ downloadRuntime(selectedDirectory, destinationDirectory, del);
+ }
+
+ private void downloadRuntime(final String selectedDirectory,
+ final String destinationDirectory, final boolean deleteOnExit) {
+ final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ dialog.setBlockOnOpen(false);
+ dialog.setCancelable(true);
+ dialog.open();
+ final IProgressMonitor monitor = dialog.getProgressMonitor();
+ monitor.beginTask("Download '" + downloadRuntime.getName() + "'
...", 100);
+
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ downloadAndInstall(selectedDirectory,
+ destinationDirectory, deleteOnExit, monitor);
+ }
+ };
+ try {
+ dialog.run(true, true, runnable);
+ } catch (Exception e) {
+ RuntimeCoreActivator.log(e);
+ MessageDialog.openError(getActiveShell(), "Error", e.getMessage());
+ }
+ }
+
+ private IStatus downloadAndInstall(String selectedDirectory, String
destinationDirectory, boolean deleteOnExit, IProgressMonitor monitor) {
+ FileInputStream in = null;
+ OutputStream out = null;
+ File file = null;
+ try {
+ URL url = new URL(downloadRuntime.getUrl());
+ String name = url.getPath();
+ int slashIdx = name.lastIndexOf('/');
+ if (slashIdx >= 0)
+ name = name.substring(slashIdx + 1);
+
+ File destination = new File(destinationDirectory);
+ destination.mkdirs();
+ file = new File (destination, name);
+ int i = 1;
+ while (file.exists()) {
+ file = new File(destination, name + "(" + i++ + ")");
+ }
+
+ if (deleteOnExit) {
+ file.deleteOnExit();
+ }
+ out = new BufferedOutputStream(
+ new FileOutputStream(file));
+
+ IStatus result = ECFExamplesTransport.getInstance().download(file.getName(),
+ url.toExternalForm(), out, monitor);
+ out.flush();
+ out.close();
+ if (monitor.isCanceled()) {
+ file.deleteOnExit();
+ file.delete();
+ return Status.CANCEL_STATUS;
+ }
+ File directory = new File(selectedDirectory);
+ directory.mkdirs();
+ if (!directory.isDirectory()) {
+ RuntimeCoreActivator.getDefault().getLog().log(result);
+ MessageDialog.openError(getActiveShell(), "Error", "The '" +
directory + "' is not a directory.");
+ file.deleteOnExit();
+ file.delete();
+ return Status.CANCEL_STATUS;
+ }
+ ProjectExamplesActivator.extractZipFile(file, directory, monitor);
+ if (!result.isOK()) {
+ RuntimeCoreActivator.getDefault().getLog().log(result);
+ String message;
+ if (result.getException() != null) {
+ message = result.getException().getMessage();
+ } else {
+ message = result.getMessage();
+ }
+ MessageDialog.openError(getActiveShell(), "Error", message);
+ file.deleteOnExit();
+ file.delete();
+ return Status.CANCEL_STATUS;
+ }
+ createRuntimes(selectedDirectory, monitor);
+ } catch (IOException e) {
+ RuntimeCoreActivator.log(e);
+ if (file != null && file.exists()) {
+ file.deleteOnExit();
+ file.delete();
+ }
+ MessageDialog.openError(getActiveShell(), "Error", e.getMessage());
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ private Shell getActiveShell() {
+ Display display = Display.getDefault();
+ if (display != null) {
+ return display.getActiveShell();
+ }
+ return null;
+ }
+
+ private static void createRuntimes(String directory, IProgressMonitor monitor) {
+ JBossRuntimeLocator locator = new JBossRuntimeLocator();
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ .getRuntimePaths();
+ RuntimePath newPath = new RuntimePath(directory);
+ runtimePaths.add(newPath);
+ for (RuntimePath runtimePath : runtimePaths) {
+ List<ServerDefinition> serverDefinitions = locator
+ .searchForRuntimes(runtimePath.getPath(),
+ monitor);
+ runtimePath.getServerDefinitions().clear();
+ for (ServerDefinition serverDefinition : serverDefinitions) {
+ serverDefinition.setRuntimePath(runtimePath);
+ }
+ runtimePath.getServerDefinitions().addAll(serverDefinitions);
+ RuntimeUIActivator.getDefault().getRuntimePaths().add(runtimePath);
+ RuntimeUIActivator.getDefault().saveRuntimePaths();
+ }
+ List<ServerDefinition> serverDefinitions = RuntimeUIActivator
+ .getDefault().getServerDefinitions();
+ Set<IRuntimeDetector> detectors = RuntimeCoreActivator
+ .getRuntimeDetectors();
+ for (IRuntimeDetector detector : detectors) {
+ if (detector.isEnabled()) {
+ detector.initializeRuntimes(serverDefinitions);
+ }
+ }
+ }
+
+}
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeViewerDialog.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeViewerDialog.java
(rev 0)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/DownloadRuntimeViewerDialog.java 2011-10-16
21:09:55 UTC (rev 35691)
@@ -0,0 +1,188 @@
+/*************************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, 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:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.runtime.ui.dialogs;
+
+import java.util.Map;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnLayoutData;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.model.DownloadRuntime;
+
+/**
+ * @author snjeza
+ *
+ */
+public class DownloadRuntimeViewerDialog extends Dialog {
+
+ private TableViewer viewer;
+ private Map<String, DownloadRuntime> downloadRuntimes;
+
+ public DownloadRuntimeViewerDialog(Shell parentShell) {
+ super(parentShell);
+ setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
+ | SWT.RESIZE | getDefaultOrientation());
+ downloadRuntimes = RuntimeCoreActivator.getDefault().getDownloadJBossRuntimes();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ getShell().setText("Runtimes");
+ Composite area = (Composite) super.createDialogArea(parent);
+ area.setLayout(new GridLayout());
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout(1, false));
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ viewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.heightHint = 400;
+ gd.widthHint = 700;
+ viewer.getTable().setLayoutData(gd);
+
+ Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ table.setFont(parent.getFont());
+
+ viewer.setContentProvider(new DownloadRuntimesContentProvider());
+
+ //String[] columnHeaders = {"Name", "ID", "Version",
"URL"};
+ String[] columnHeaders = {"Name", "ID", "Version"};
+ for (int i = 0; i < columnHeaders.length; i++) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.setLabelProvider(new DownloadRuntimesLabelProvider(i));
+ column.getColumn().setText(columnHeaders[i]);
+ column.getColumn().setResizable(true);
+ column.getColumn().setMoveable(true);
+ }
+
+ ColumnLayoutData[] runtimePathsLayouts= {
+ new ColumnWeightData(250,250),
+ new ColumnWeightData(200,200),
+ new ColumnWeightData(150,150),
+
+ };
+
+ TableLayout layout = new AutoResizeTableLayout(table);
+ for (int i = 0; i < runtimePathsLayouts.length; i++) {
+ layout.addColumnData(runtimePathsLayouts[i]);
+ }
+
+ viewer.setInput(downloadRuntimes);
+ if (downloadRuntimes.values().size() > 0) {
+ viewer.getTable().select(0);
+ }
+ viewer.getTable().setLayout(layout);
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ validate();
+ }
+ });
+ return area;
+ }
+
+ class DownloadRuntimesContentProvider implements IStructuredContentProvider {
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return downloadRuntimes.values().toArray(new DownloadRuntime[0]);
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+ }
+
+ class DownloadRuntimesLabelProvider extends ColumnLabelProvider {
+
+ private int columnIndex;
+
+ public DownloadRuntimesLabelProvider(int i) {
+ this.columnIndex = i;
+ }
+
+ public String getText(Object element) {
+ if (element instanceof DownloadRuntime) {
+ DownloadRuntime downloadRuntime = (DownloadRuntime) element;
+ switch (columnIndex) {
+ case 0:
+ return downloadRuntime.getName();
+ case 1:
+ return downloadRuntime.getId();
+ case 2:
+ return downloadRuntime.getVersion();
+ case 3:
+ return downloadRuntime.getUrl();
+ }
+ }
+ return null;
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ ISelection selection = viewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ Object object = structuredSelection.getFirstElement();
+ if (object instanceof DownloadRuntime) {
+ DownloadRuntime downloadRuntime = (DownloadRuntime) object;
+ DownloadRuntimeDialog dialog = new DownloadRuntimeDialog(getShell(),
downloadRuntime);
+ dialog.open();
+ }
+ }
+ super.okPressed();
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ validate();
+ }
+
+ protected void validate() {
+ getButton(IDialogConstants.OK_ID).setEnabled(viewer.getSelection() != null);
+ }
+
+}
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2011-10-16
20:40:50 UTC (rev 35690)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2011-10-16
21:09:55 UTC (rev 35691)
@@ -73,6 +73,8 @@
import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
import org.jboss.tools.runtime.ui.dialogs.AutoResizeTableLayout;
+import org.jboss.tools.runtime.ui.dialogs.DownloadRuntimeDialog;
+import org.jboss.tools.runtime.ui.dialogs.DownloadRuntimeViewerDialog;
import org.jboss.tools.runtime.ui.dialogs.EditRuntimePathDialog;
import org.jboss.tools.runtime.ui.dialogs.RuntimePathEditingSupport;
@@ -93,6 +95,7 @@
private Set<IRuntimeDetector> runtimeDetectors;
private TableViewer detectorViewer;
private Button searchButton;
+ private Button downloadButton;
/*
* (non-Javadoc)
@@ -404,6 +407,22 @@
}
});
+ downloadButton = new Button(buttonComposite, SWT.PUSH);
+ downloadButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ downloadButton.setText("Download...");
+
+ downloadButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ DownloadRuntimeViewerDialog dialog = new DownloadRuntimeViewerDialog(getShell());
+ dialog.open();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {