diff options
Diffstat (limited to 'examples/org.eclipse.swt.examples.launcher/src')
6 files changed, 0 insertions, 1000 deletions
diff --git a/examples/org.eclipse.swt.examples.launcher/src/import.properties b/examples/org.eclipse.swt.examples.launcher/src/import.properties deleted file mode 100644 index 58344f0d3e..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/import.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2003 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -# Persist project settings for later import -natures = org.eclipse.jdt.core.javanature; org.eclipse.pde.PluginNature -builders = org.eclipse.jdt.core.javabuilder; org.eclipse.pde.ManifestBuilder; org.eclipse.pde.SchemaBuilder -var.ECLIPSE_PLUGINS = <<ECLIPSE_PLUGINS>> diff --git a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemDescriptor.java b/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemDescriptor.java deleted file mode 100755 index 7ec10195b8..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemDescriptor.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.examples.launcher; - - -import org.eclipse.swt.graphics.*; - -/** - * ItemDescriptor collects information about a launch item. - */ -class ItemDescriptor { - private String id; - private String name; - private String description; - private Image icon; - private String view; - private String mainType; - private String pluginId; - - - /** - * Constructs an ItemDescriptor. - * - * @param id the id - * @param name the name - * @param description the description - * @param icon the icon - * @param view the host view may be null if it is a standalone application - * @param mainType the fully qualified class name to run may be null if it is a view - * @param pluginId the name of the plugin which contains the main class - */ - public ItemDescriptor(String id, String name, String description, - Image icon, String view, String mainType, String pluginId) { - this.id = id; - this.name = name; - this.description = description; - this.icon = icon; - this.view = view; - this.mainType = mainType; - this.pluginId = pluginId; - } - - /** - * Returns the ID for this program. - * - * @return the user-specified ID for this program - */ - public String getId() { - return id; - } - - /** - * Returns the translated name for the program. - * - * @return the name of the program - */ - public String getName() { - return name; - } - - /** - * Returns a short description for the program. - * - * @return a newline-delimited string describing the program, null if no description is available - */ - public String getDescription() { - return description; - } - - /** - * Returns an icon for this descriptor - * - * @returns an icon, null if the item is a folder - */ - public Image getIcon() { - return icon; - } - - /** - * Returns the host view for the program. - * - * @return the host view, null if the item is a standalone program. - */ - public String getView () { - return view; - } - - /** - * Returns the fully qualified class to run - * for the program. - * - * @return the class to run for the program. - */ - public String getMainType () { - return mainType; - } - - /** - * Returns the name of the plugin that contains the program. - * - * @return the name of the plugin that contains the program. - */ - public String getPluginId () { - return pluginId; - } - - /** - * Determines if an item is a folder. - * - * @return true if the item is a folder - */ - public boolean isFolder() { - return (mainType == null && view == null); - } - - /** - * Determines the equality of descriptors. - * - * @return true if this.getId().equalsIgnoreCase(other.getId()) - */ - public boolean equals(Object other) { - if (other instanceof ItemDescriptor) { - ItemDescriptor otherDescriptor = (ItemDescriptor) other; - return getId().equalsIgnoreCase(otherDescriptor.getId()); - } - return false; - } - - /** - * Produces a hashcode. - * - * @return the hashcode - */ - public int hashCode() { - return id.toUpperCase().hashCode(); - } -} diff --git a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemTreeNode.java b/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemTreeNode.java deleted file mode 100755 index 6088090e96..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/ItemTreeNode.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.examples.launcher; - - -/** - * Internal class used to store tree structures of ItemDescriptors - */ -class ItemTreeNode { - private ItemTreeNode nextSibling; - private ItemTreeNode firstChild; - private ItemDescriptor descriptor; - - /** - * Constructs a leaf ItemTreeNode with a given descriptor. - * - * @param descriptor the descriptor - */ - public ItemTreeNode(ItemDescriptor descriptor) { - this.descriptor = descriptor; - } - - /** - * Adds a node to the Tree in sorted order by name. - * - * @param node the node to add. Note that node.nextSibling must be null - */ - public void addSortedNode(ItemTreeNode node) { - if (firstChild == null) { - firstChild = node; - } else if (firstChild.descriptor.getName().compareTo(node.descriptor.getName()) > 0) { - node.nextSibling = firstChild; - firstChild = node; - } else { - ItemTreeNode cursor; - for (cursor = firstChild; cursor.nextSibling != null; cursor = cursor.nextSibling) { - ItemTreeNode sibling = cursor.nextSibling; - if (sibling.descriptor.getName().compareTo(node.descriptor.getName()) > 0) break; - } - node.nextSibling = cursor.nextSibling; - cursor.nextSibling = node; - } - } - - /** - * Returns the descriptor for this node. - * - * @return the descriptor - */ - public ItemDescriptor getDescriptor() { - return descriptor; - } - - /** - * Returns the next sibling of this node. - * - * @return the next sibling, or null if none - */ - public ItemTreeNode getNextSibling() { - return nextSibling; - } - - /** - * Returns the first child of this node. - * - * @return the first child, or null if none - */ - public ItemTreeNode getFirstChild() { - return firstChild; - } -} diff --git a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherPlugin.java b/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherPlugin.java deleted file mode 100755 index 2d6abb35f5..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherPlugin.java +++ /dev/null @@ -1,390 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.examples.launcher; - - -import java.io.*; -import java.net.*; -import java.text.*; -import java.util.*; - -import org.eclipse.core.runtime.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.ui.plugin.*; - -/** - * The main plugin class to be used in the desktop. - */ -public class LauncherPlugin extends AbstractUIPlugin { - //The shared instance. - private static LauncherPlugin plugin; - private static ResourceBundle resourceBundle; - - private static final String - LAUNCH_ITEMS_POINT_ID = "org.eclipse.swt.examples.launcher.launchItems", - LAUNCH_ITEMS_XML_CATEGORY = "category", - LAUNCH_ITEMS_XML_ITEM = "item", - LAUNCH_ITEMS_XML_ITEM_ICON = "icon", - LAUNCH_ITEMS_XML_ITEM_DESCRIPTION = "description", - LAUNCH_ITEMS_XML_PROGRAM = "program", - LAUNCH_ITEMS_XML_PROGRAM_PLUGIN = "pluginId", - LAUNCH_ITEMS_XML_PROGRAM_CLASS = "mainClass", - LAUNCH_ITEMS_XML_VIEW = "view", - LAUNCH_ITEMS_XML_VIEW_VIEWID = "viewId", - LAUNCH_ITEMS_XML_ATTRIB_ID = "id", - LAUNCH_ITEMS_XML_ATTRIB_NAME = "name", - LAUNCH_ITEMS_XML_ATTRIB_ENABLED = "enabled", - LAUNCH_ITEMS_XML_ATTRIB_CATEGORY = "category", - LAUNCH_ITEMS_XML_VALUE_TRUE = "true", - LAUNCH_ITEMS_XML_VALUE_FALSE = "false"; - - static final int - liClosedFolder = 0, - liOpenFolder = 1, - liGenericExample = 2; - static final String[] imageLocations = { - "icons/closedFolder.gif", - "icons/openFolder.gif", - "icons/generic_example.gif" }; - static Image images[]; - - /** - * Constructs the LauncherPlugin. - */ - public LauncherPlugin(IPluginDescriptor descriptor) { - super(descriptor); - plugin = this; - resourceBundle = descriptor.getResourceBundle(); - } - - /** - * Clean up - */ - public void shutdown() throws CoreException { - super.shutdown(); - freeResources(); - } - - /** - * Returns the shared instance. - */ - public static LauncherPlugin getDefault() { - return plugin; - } - - /** - * Loads the resources - */ - public static void initResources() { - if (images == null) { - images = new Image[imageLocations.length]; - - for (int i = 0; i < imageLocations.length; ++i) { - images[i] = getImageFromPlugin(plugin.getDescriptor(), imageLocations[i]); - if (images[i] == null) { - freeResources(); - logError(getResourceString("error.CouldNotLoadResources"), null); - throw new IllegalStateException(); - } - } - } - } - - /** - * Frees the resources - */ - public static void freeResources() { - if (images != null) { - for (int i = 0; i < images.length; ++i) { - final Image image = images[i]; - if (image != null) image.dispose(); - } - images = null; - } - } - - /** - * Log an error to the ILog for this plugin - * - * @param message the localized error message text - * @param exception the associated exception, or null - */ - public static void logError(String message, Throwable exception) { - plugin.getLog().log(new Status(IStatus.ERROR, plugin.getDescriptor().getUniqueIdentifier(), - 0, message, exception)); - } - - /** - * Returns a string from the resource bundle. - * We don't want to crash because of a missing String. - * Returns the key if not found. - */ - public static String getResourceString(String key) { - try { - return resourceBundle.getString(key); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; - } - } - - /** - * Returns a string from the resource bundle and binds it - * with the given arguments. If the key is not found, - * return the key. - */ - public static String getResourceString(String key, Object[] args) { - try { - return MessageFormat.format(getResourceString(key), args); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; - } - } - - /** - * Constructs a list of available programs from registered extensions. - * - * @return an ItemTreeNode representing the root of a tree of items (the root is not to be displayed) - */ - public static ItemTreeNode getLaunchItemTree() { - ItemTreeNode categoryTree = - new ItemTreeNode(new ItemDescriptor("<<Root>>", "<<Root>>", null, null, null, null, null)); - - // get the platform's public plugin registry - IPluginRegistry pluginRegistry = Platform.getPluginRegistry(); - // retrieve all configuration elements registered at our launchItems extension-point - IConfigurationElement[] configurationElements = - pluginRegistry.getConfigurationElementsFor(LAUNCH_ITEMS_POINT_ID); - - if (configurationElements == null || configurationElements.length == 0) { - logError(getResourceString("error.CouldNotFindRegisteredExtensions"), null); - return categoryTree; - } - - /* Collect all launch categories -- coalesce those with same ID */ - HashMap idMap = new HashMap(); - for (int i = 0; i < configurationElements.length; ++i) { - final IConfigurationElement ce = configurationElements[i]; - final String ceName = ce.getName(); - final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null); - - if (idMap.containsKey(attribId)) continue; - if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) { - final String attribName = getItemName(ce); - ItemDescriptor theDescriptor = new ItemDescriptor(attribId, attribName, - getItemDescription(ce), null, null, null, null); - idMap.put(attribId, new ItemTreeNode(theDescriptor)); - } - } - - /* Generate launch category hierarchy */ - Set tempIdSet = new HashSet(); // used to prevent duplicates from being entered into the tree - for (int i = 0; i < configurationElements.length; ++i) { - final IConfigurationElement ce = configurationElements[i]; - final String ceName = ce.getName(); - final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null); - - if (tempIdSet.contains(attribId)) continue; - if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) { - final ItemTreeNode theNode = (ItemTreeNode) idMap.get(attribId); - addItemByCategory(ce, categoryTree, theNode, idMap); - tempIdSet.add(attribId); - } - } - - /* Generate program tree */ - for (int i = 0; i < configurationElements.length; ++i) { - final IConfigurationElement ce = configurationElements[i]; - final String ceName = ce.getName(); - final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null); - - if (idMap.containsKey(attribId)) continue; - if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) { - // ignore - } else if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_ITEM)) { - final String enabled = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ENABLED, - LAUNCH_ITEMS_XML_VALUE_TRUE); - if (enabled.equalsIgnoreCase(LAUNCH_ITEMS_XML_VALUE_FALSE)) continue; - ItemDescriptor theDescriptor = createItemDescriptor(ce, attribId); - - if (theDescriptor != null) { - final ItemTreeNode theNode = new ItemTreeNode(theDescriptor); - addItemByCategory(ce, categoryTree, theNode, idMap); - idMap.put(attribId, theNode); - } - } - } - return categoryTree; - } - - - /** - * Adds an item to the category tree. - */ - private static void addItemByCategory(IConfigurationElement ce, ItemTreeNode root, - ItemTreeNode theNode, HashMap idMap) { - final String attribCategory = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_CATEGORY, null); - - // locate the parent node - ItemTreeNode parentNode = null; - if (attribCategory != null) { - parentNode = (ItemTreeNode) idMap.get(attribCategory); - } - if (parentNode == null) parentNode = root; - - // add the item - parentNode.addSortedNode(theNode); - } - - /** - * Creates an ItemDescriptor from an XML definition. - * - * @param ce the IConfigurationElement describing the item - * @param attribId the attribute id - * @return a new ItemDescriptor, or null if an error occurs - */ - private static ItemDescriptor createItemDescriptor(IConfigurationElement ce, String attribId) { - final String attribName = getItemName(ce); - final Image attribIcon = getItemIcon(ce); - final String attribDescription = getItemDescription(ce); - - IConfigurationElement viewCE = getItemElement(ce, LAUNCH_ITEMS_XML_VIEW); - if (viewCE != null) { - //Item is a view - final String attribView = getItemAttribute(viewCE, LAUNCH_ITEMS_XML_VIEW_VIEWID, null); - if (attribView == null) { - logError(getResourceString("error.IncompleteViewLaunchItem", - new Object[] { attribId } ), null); - return null; - } - return new ItemDescriptor(attribId, attribName, attribDescription, - attribIcon, attribView, null, null); - } else { - //Item is a standalone - IConfigurationElement programCE = getItemElement(ce, LAUNCH_ITEMS_XML_PROGRAM); - if (programCE != null) { - final String attribPluginId = getItemAttribute(programCE, LAUNCH_ITEMS_XML_PROGRAM_PLUGIN, null); - final String attribClass = getItemAttribute(programCE, LAUNCH_ITEMS_XML_PROGRAM_CLASS, null); - if (attribClass == null || attribPluginId == null) { - logError(getResourceString("error.IncompleteProgramLaunchItem", - new Object[] { attribId } ), null); - return null; - } - return new ItemDescriptor(attribId, attribName, attribDescription, - attribIcon, null, attribClass, attribPluginId); - } else { - logError(getResourceString("error.IncompleteLaunchItem", - new Object[] { attribId } ), null); - return null; - } - } - } - - /** - * Returns the first instance of a particular child XML element. - * - * @param ce the IConfigurationElement parent - * @param element the name of the element to fetch - * @return the element's IConfigurationElement, or null if not found - */ - private static IConfigurationElement getItemElement(IConfigurationElement ce, String element) { - IConfigurationElement[] elementCEs = ce.getChildren(element); - return (elementCEs != null && elementCEs.length != 0) ? elementCEs[0] : null; - } - - /** - * Returns the value of an XML attribute for an item. - * - * @param ce the IConfigurationElement describing the item - * @param attribute the attribute to fetch - * @param defaultValue the value to return if the attribute is not found - * @return the attribute value - */ - private static String getItemAttribute(IConfigurationElement ce, String attribute, String defaultValue) { - String value = ce.getAttribute(attribute); - return (value != null) ? value : defaultValue; - } - - /** - * Returns the description string given the IConfigurationElement for an item. - * - * @param ce the IConfigurationElement describing the item - * @return a newline-delimited string that describes this item, or null if none - */ - private static String getItemDescription(IConfigurationElement ce) { - String description = getItemAttribute(ce, LAUNCH_ITEMS_XML_ITEM_DESCRIPTION, ""); - return (description.length() == 0) ? null : description; - } - - /** - * Returns the name of an item. - * - * @param ce the IConfigurationElement describing the item - * @return the attribute value - */ - private static String getItemName(IConfigurationElement ce) { - return getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_NAME, - getResourceString("launchitem.Missing.name")); - } - - - /** - * Returns the icon for an item. - * - * @param ce the IConfigurationElement describing the item - * @return an icon - */ - private static Image getItemIcon(IConfigurationElement ce) { - String iconPath = getItemAttribute(ce, LAUNCH_ITEMS_XML_ITEM_ICON, ""); - if (iconPath.length() != 0) { - Image icon = getImageFromPlugin(ce.getDeclaringExtension().getDeclaringPluginDescriptor(), - iconPath); - if (icon != null) { - Image[] newImages = new Image[images.length + 1]; - System.arraycopy(images, 0, newImages, 0, images.length); - newImages[images.length] = icon; - images = newImages; - return icon; - } - } - return images[liGenericExample]; - } - - /** - * Gets an image from a path relative to the plugin install directory. - * - * @param pd the plugin descriptor for the plugin with the image - * @param iconPath the path relative to the install directory - * @return the image, or null if not found - */ - private static Image getImageFromPlugin(IPluginDescriptor pd, String iconPath) { - InputStream is = null; - try { - URL installUrl = pd.getInstallURL(); - URL url = new URL(installUrl, iconPath); - is = url.openConnection().getInputStream(); - ImageData source = new ImageData(is); - ImageData mask = source.getTransparencyMask(); - Image image = new Image(null, source, mask); - return image; - } catch (Throwable ex) { - return null; - } finally { - try { - if (is != null) is.close(); - } catch (IOException e) { - } - } - } -} diff --git a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherView.java b/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherView.java deleted file mode 100755 index 663dfd6415..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherView.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.examples.launcher; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.*; -import org.eclipse.ui.part.*; -import java.lang.reflect.*; - -/** - * Launcher uses <code>org.eclipse.swt</code> - * to launch the other registered examples. - * - * @see ViewPart - */ -public class LauncherView extends ViewPart { - private Shell workbenchShell; - - private Tree launchTree; - private Text descriptionText; - private Button runButton; - - /** - * Constructs a LauncherView. - */ - public LauncherView() { - LauncherPlugin.initResources(); - } - - /** - * Creates the example. - * - * @see ViewPart#createPartControl - */ - public void createPartControl(Composite parent) { - workbenchShell = getSite().getShell(); - parent.setLayout(new SplitLayout()); - - Group launchGroup = new Group(parent, SWT.NULL); - launchGroup.setText(LauncherPlugin.getResourceString("view.launchGroup.text")); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - launchGroup.setLayout(gridLayout); - - launchTree = new Tree(launchGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); - gridData.horizontalSpan = 2; - launchTree.setLayoutData(gridData); - launchTree.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - final ItemDescriptor item = getSelectedItem(); - setDescriptionByItem(item); - } - public void widgetDefaultSelected(SelectionEvent event) { - final ItemDescriptor item = getSelectedItem(); - setDescriptionByItem(item); - launchItem(getSelectedItem()); - } - }); - launchTree.addTreeListener(new TreeListener() { - public void treeCollapsed(TreeEvent event) { - final TreeItem item = (TreeItem) event.item; - if (item == null) return; - item.setImage(LauncherPlugin.images[LauncherPlugin.liClosedFolder]); - } - public void treeExpanded(TreeEvent event) { - final TreeItem item = (TreeItem) event.item; - if (item == null) return; - item.setImage(LauncherPlugin.images[LauncherPlugin.liOpenFolder]); - } - }); - - runButton = new Button(launchGroup, SWT.PUSH); - runButton.setText(LauncherPlugin.getResourceString("view.launchButton.text")); - runButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - launchItem(getSelectedItem()); - } - public void widgetDefaultSelected(SelectionEvent event) { - } - }); - - Group descriptionGroup = new Group(parent, SWT.NULL); - descriptionGroup.setText(LauncherPlugin.getResourceString("view.descriptionGroup.text")); - descriptionGroup.setLayout(new FillLayout()); - - descriptionText = new Text(descriptionGroup, SWT.MULTI | SWT.BORDER | - SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); - - setDescriptionByItem(null); - setItemDescriptors(LauncherPlugin.getLaunchItemTree()); - } - - /** - * Called when we must grab focus. - * - * @see org.eclipse.ui.part.ViewPart#setFocus - */ - public void setFocus() { - launchTree.setFocus(); - runButton.getShell().setDefaultButton(runButton); - } - - /** - * Called when the View is to be disposed - */ - public void dispose() { - workbenchShell = null; - launchTree = null; - descriptionText = null; - runButton = null; - super.dispose(); - } - - /** - * Installs a new launch list. - * - * @param newRoot the new tree of launch items for the UI - */ - public void setItemDescriptors(final ItemTreeNode newRoot) { - if (workbenchShell == null) return; - workbenchShell.getDisplay().syncExec(new Runnable() { - public void run() { - if ((launchTree == null) || (launchTree.isDisposed())) return; - launchTree.removeAll(); - - for (ItemTreeNode node = newRoot.getFirstChild(); node != null; - node = node.getNextSibling()) { - doNode(node, new TreeItem(launchTree, SWT.NONE)); // top-level TreeItem - } - } - private void addGroup(TreeItem parent, ItemTreeNode node) { - for (;node != null; node = node.getNextSibling()) { - doNode(node, new TreeItem(parent, SWT.NONE)); // TreeItem at depth > 0 - } - } - private void doNode(ItemTreeNode node, TreeItem treeItem) { - final ItemDescriptor item = node.getDescriptor(); - treeItem.setText(item.getName()); - treeItem.setData(item); - if (node.getDescriptor().isFolder()) { - treeItem.setExpanded(false); - treeItem.setImage(LauncherPlugin.images[LauncherPlugin.liClosedFolder]); - } else { - treeItem.setImage(node.getDescriptor().getIcon()); - } - addGroup(treeItem, node.getFirstChild()); - } - }); - } - - /** - * Runs the specified launch item. - * - * @param itemDescriptor the launch item to execute - */ - private void launchItem(ItemDescriptor itemDescriptor) { - /* Case 1: The launch item is a view */ - String pluginViewId = itemDescriptor.getView (); - if (pluginViewId != null) { - final IWorkbenchPart workbenchPart = this; - final IWorkbenchPartSite workbenchPartSite = workbenchPart.getSite(); - final IWorkbenchPage workbenchPage = workbenchPartSite.getPage(); - try { - workbenchPage.showView(pluginViewId); - } catch (PartInitException e) { - LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.Invocation"), e); - } - return; - } - /* Case 2: The launch item is a standalone program */ - if (workbenchShell == null) return; - try { - Class cl = Class.forName(itemDescriptor.getMainType()); - Display display = workbenchShell.getDisplay(); - Object exampleInstance = cl.newInstance(); - Method openMethod = cl.getDeclaredMethod("open", new Class[] {Display.class}); - openMethod.invoke(exampleInstance, new Object[] {display}); - } catch (NoSuchMethodException e) { - LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.DoesNotImplementMethod"), null); - } catch (ClassNotFoundException e) { - LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.CouldNotFindClass"), e); - } catch (Exception e) { - LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.CouldNotInstantiateClass"), e); - } - } - - /** - * Obtains the selected launch item. - * - * @return the currently selected ItemDescriptor - */ - private ItemDescriptor getSelectedItem() { - final TreeItem[] selections = launchTree.getSelection(); - if (selections.length == 0) return null; - final ItemDescriptor itemDescriptor = (ItemDescriptor) selections[0].getData(); - return itemDescriptor; - } - - /** - * Sets the currently visible description text to reflect that of a particular ItemDescriptor. - * - * @param itemDescriptor the launch item whose description is to be displayed, or null if none - */ - private void setDescriptionByItem(ItemDescriptor itemDescriptor) { - String description; - if (itemDescriptor == null) { - description = LauncherPlugin.getResourceString("launchitem.Null.description"); - if (runButton != null) runButton.setEnabled(false); - } else { - description = itemDescriptor.getDescription(); - if (description == null) - description = LauncherPlugin.getResourceString("launchitem.Missing.description"); - if (runButton != null) { - runButton.setEnabled(itemDescriptor.getView() != null || itemDescriptor.getMainType() != null); - } - } - descriptionText.setText(description); - } -} diff --git a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/SplitLayout.java b/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/SplitLayout.java deleted file mode 100755 index 47dbfddd89..0000000000 --- a/examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/SplitLayout.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.examples.launcher; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * A Layout class that automatically switches from a horizontal split to a vertical - * split layout to accomodate changing size conditions. - * - * Later on we might improve this class to take into account the "preferred" size of - * the widgets. - */ -public class SplitLayout extends Layout { - private static final int - splitHorizontally = 0, - splitVertically = 1; - private int splitDirection = splitHorizontally; - - public int spacing = 3; - public int marginTop = 3; - public int marginLeft = 3; - public int marginRight = 3; - public int marginBottom = 3; - - /** - * Creates a new layout - */ - public SplitLayout() { - } - - /** - * @see Layout#computeSize(Composite, int, int, boolean) - */ - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { - if (wHint == SWT.DEFAULT) { - if (hHint == SWT.DEFAULT) { - Point hSplitSize = computeHSplitSize(composite, wHint, hHint, flushCache); - Point vSplitSize = computeVSplitSize(composite, wHint, hHint, false); - int hSplitArea = hSplitSize.x * hSplitSize.y; - int vSplitArea = vSplitSize.x * vSplitSize.y; - // Choose direction consuming least area - if (hSplitArea < vSplitArea) { - splitDirection = splitHorizontally; - return hSplitSize; - } else { - splitDirection = splitVertically; - return vSplitSize; - } - } else { - // Constrained in height: split vertically - splitDirection = splitVertically; - return computeVSplitSize(composite, wHint, hHint, flushCache); - } - } else { - if (hHint == SWT.DEFAULT) { - // Constrained in width: split horizontally - splitDirection = splitHorizontally; - return computeHSplitSize(composite, wHint, hHint, flushCache); - } else { - if (hHint < wHint) { - splitDirection = splitVertically; - return computeVSplitSize(composite, wHint, hHint, flushCache); - } else { - splitDirection = splitHorizontally; - return computeHSplitSize(composite, wHint, hHint, flushCache); - } - } - } - } - /** - * @see Layout#layout(Composite, boolean) - */ - protected void layout(Composite composite, boolean flushCache) { - Rectangle clientArea = composite.getClientArea(); - computeSize(composite, clientArea.width, clientArea.height, false); - - Control[] children = composite.getChildren(); - clientArea.x += marginLeft; - clientArea.y += marginTop; - clientArea.width -= marginRight + marginLeft; - clientArea.height -= marginBottom + marginTop; - Point position = new Point(clientArea.x, clientArea.y); - - for (int i = 0; i < children.length; ++i) { - final Control child = children[i]; - final Rectangle bounds; - if (splitDirection == splitHorizontally) { - int height = clientArea.height / children.length; - bounds = new Rectangle(position.x, position.y, clientArea.width, height); - position.y += height + spacing; - } else { - int width = clientArea.width / children.length; - bounds = new Rectangle(position.x, position.y, width, clientArea.height); - position.x += width + spacing; - } - bounds.width = Math.max(bounds.width, 0); - bounds.height = Math.max(bounds.height, 0); - child.setBounds(bounds); - } - } - - private Point computeHSplitSize(Composite composite, int wHint, int hHint, boolean flushCache) { - Point size = new Point(marginLeft + marginRight, marginTop + marginBottom); - Control[] children = composite.getChildren(); - for (int i = 0; i < children.length; ++i) { - final Control child = children[i]; - - Point childSize = child.computeSize(wHint, hHint, flushCache); - size.x = Math.max(size.x, childSize.x); - size.y += childSize.y + spacing; - } - return size; - } - - private Point computeVSplitSize(Composite composite, int wHint, int hHint, boolean flushCache) { - Point size = new Point(marginLeft + marginRight, marginTop + marginBottom); - Control[] children = composite.getChildren(); - for (int i = 0; i < children.length; ++i) { - final Control child = children[i]; - - Point childSize = child.computeSize(wHint, hHint, flushCache); - size.x += childSize.x + spacing; - size.y = Math.max(size.y, childSize.y); - } - return size; - } -} |