diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt')
9 files changed, 0 insertions, 1485 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/DisplayUtil.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/DisplayUtil.java deleted file mode 100644 index 0c9c93447..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/DisplayUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.ui.swt; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; - -/** - * Utility providing convenience methods to use the SWT Display. - */ -public class DisplayUtil { - - /** - * Does what Display does in syncExec, but ensures - * that the exec is not executed if the display is - * currently being disposed or already unset. - * - * @param exec the Runnable to be executed. - * - * @see Display#asyncExec(Runnable) - * @see Runnable#run() - */ - public static void safeSyncExec(Runnable exec){ - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.syncExec(exec); - } - catch (Exception e) { - // if display is disposed, silently ignore. - } - } - /** - * Does what Display does in timerExec, but ensures - * that the exec is not executed if the display is - * currently being disposed or already unset. - * - * @param exec the Runnable to be executed. - * @param millisec time to wait. - * - * @see Display#timerExec(int, Runnable) - * @see Runnable#run() - */ - public static void safeTimerExec(Runnable exec, int millisec){ - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.timerExec(millisec,exec); - } - catch (Exception e) { - // if display is disposed, silently ignore. - } - } - - /** - * Does what Display does in asyncExec, but ensures - * that the exec is not executed if the display is - * currently being disposed or already unset. - * - * @param exec The Runnable to be executed. - * - * @see Display#asyncExec(Runnable) - * @see Runnable#run() - */ - public static void safeAsyncExec(Runnable exec){ - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(exec); - } - catch (Exception e) { - // if display is disposed, silently ignore. - } - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/SWTControlUtil.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/SWTControlUtil.java deleted file mode 100644 index 84b0479e7..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/SWTControlUtil.java +++ /dev/null @@ -1,713 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.ui.swt; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Decorations; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Scrollable; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.PlatformUI; - -/** - * Utility providing convenience methods for use with SWT controls. - */ -public final class SWTControlUtil { - - /** - * Returns the text from the specified control. The method will return <code>null</code> - * if the control is <code>null</code> or has been already disposed. - * - * @param control The control to get the text from. - * @param The text currently set to the control or <code>null</code>. - */ - public static final String getText(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof Button) { - return ((Button)control).getText().trim(); - } - if (control instanceof Combo) { - return ((Combo)control).getText().trim(); - } - if (control instanceof Group) { - return ((Group)control).getText().trim(); - } - if (control instanceof Label) { - return ((Label)control).getText().trim(); - } - if (control instanceof Link) { - return ((Link)control).getText().trim(); - } - if (control instanceof Text) { - return ((Text)control).getText().trim(); - } - if (control instanceof Decorations) { - return ((Decorations)control).getText(); - } - } - return null; - } - - /** - * Sets the given text to the specified control. The text will be not applied if the - * control is <code>null</code> or has been already disposed or if the given text itself - * is <code>null</code>. - * - * @param control The control the given text should be applied to. - * @param value The text to apply to the given control. - */ - public static final void setText(Control control, String value) { - if (control != null && !control.isDisposed() && value != null) { - String trimmedValue = value.trim(); - - // Avoid triggering attached listeners if the value has not changed. - String oldValue = getText(control); - if (!trimmedValue.equals(oldValue)) { - if (control instanceof Button) { - ((Button)control).setText(trimmedValue); - } - if (control instanceof Combo) { - ((Combo)control).setText(trimmedValue); - } - if (control instanceof Group) { - ((Group)control).setText(trimmedValue); - } - if (control instanceof Label) { - ((Label)control).setText(trimmedValue); - } - if (control instanceof Link) { - ((Link)control).setText(trimmedValue); - } - if (control instanceof Text) { - ((Text)control).setText(trimmedValue); - } - if (control instanceof Decorations) { - ((Decorations)control).setText(trimmedValue); - } - } - } - } - - /** - * Sets the given text to the specified control as tooltip. The tooltip text will be not - * applied if the control is <code>null</code> or has been already disposed. - * - * @param control The control the given text should be applied to. - * @param value The text to apply to the given control or <code>null</code> to reset the tooltip. - */ - public static final void setToolTipText(Control control, String value) { - if (control != null && !control.isDisposed()) { - control.setToolTipText(value); - } - } - - /** - * Sets the text of the control (Text, Combo) as tooltip if the text is - * not fully visible. - * @param control The control to set the tooltip for. - */ - public static final void setValueToolTip(Scrollable control) { - if (control != null && !control.isDisposed()) { - String text = null; - int resize = 0; - if (control instanceof Text) { - text = ((Text)control).getText().trim(); - resize = control.getBorderWidth() * 2; - } - if (control instanceof Combo) { - text = ((Combo)control).getText().trim(); - resize = (int)(control.getSize().y * 1.5) + control.getBorderWidth() * 2; - } - if (text != null) { - GC gc = new GC(control); - int width = 0; - for (int i = 0; i < text.length(); i++) { - width += gc.getAdvanceWidth(text.charAt(i)); - } - // Show the tooltip _only_ if the text itself exceeds - // the length of the control (partially shown within the control). - if (width > (control.getClientArea().width - resize)) { - control.setToolTipText(text); - } else { - control.setToolTipText(null); - } - gc.dispose(); - } - } - } - - /** - * Adds the given text to the specified control. The given text will be added in case it's not - * <code>null</code> and not empty and if the given control itself is not <code>null</code> - * and not disposed. If the given text is already within the controls drop down list, the text - * will <i>not</i> be added again to the list. - * - * @param control The control to add the given text to. - * @param value The text to add to the control. - */ - public static final void add(Control control, String value) { - add(control, value, false); - } - - /** - * Adds the given text to the specified control. The given text will be added in case it's not - * <code>null</code> and not empty and if the given control itself is not <code>null</code> - * and not disposed. If the given text is already within the controls drop down list, the text - * will <i>not</i> be added again to the list. - * - * @param control The control to add the given text to. - * @param value The text to add to the control. - * @param allowEmpty If <code>true</code>, empty values will be added to the control. Otherwise, - * empty values will be filtered out and not applied to the control. - */ - public static final void add(Control control, String value, boolean allowEmpty) { - if (control != null && !control.isDisposed() && value != null) { - if (!allowEmpty && value.trim().length() == 0) { - return; - } - if (control instanceof Combo) { - Combo combo = ((Combo)control); - if (combo.indexOf(value) == -1) { - combo.add(value); - } - } - if (control instanceof List) { - List list = ((List)control); - if (list.indexOf(value) == -1) { - list.add(value); - } - } - } - } - - /** - * Adds the given text to the specified control at the given index. If the given index is negative, - * the item index will be set to <code>0</code>. The given text will be added in case it's not - * <code>null</code> and not empty and if the given control itself is not <code>null</code> - * and not disposed. If the given text is already within the controls drop down list, the text will - * <i>not</i> be added again to the list. - * - * @param control The control to add the given text to. - * @param value The text to add to the control. - * @param index The index of the item to add to the control. - */ - public static final void add(Control control, String value, int index) { - add(control, value, index, false); - } - - /** - * Adds the given text to the specified control at the given index. If the given index is negative, - * the item index will be set to <code>0</code>. The given text will be added in case it's not - * <code>null</code> and not empty and if the given control itself is not <code>null</code> - * and not disposed. If the given text is already within the controls drop down list, the text will - * <i>not</i> be added again to the list. - * - * @param control The control to add the given text to. - * @param value The text to add to the control. - * @param index The index of the item to add to the control. - * @param allowEmpty If <code>true</code>, empty values will be added to the control. Otherwise, - * empty values will be filtered out and not applied to the control. - */ - public static final void add(Control control, String value, int index, boolean allowEmpty) { - if (control != null && !control.isDisposed() && value != null) { - if (!allowEmpty && value.trim().length() == 0) { - return; - } - if (control instanceof Combo) { - Combo combo = ((Combo)control); - if (combo.indexOf(value) == -1) { - if (index < 0) { - index = 0; - } - combo.add(value, index); - } - } - if (control instanceof List) { - List list = ((List)control); - if (list.indexOf(value) == -1) { - if (index < 0) { - index = 0; - } - list.add(value, index); - } - } - } - } - - /** - * Sets the enabled state of the given control to the given state. The state will be - * applied in case the given control is not <code>null</code> and not disposed. - * - * @param control The control to set the enabled state for. - * @param enabled <code>true</code> to enable the control, <code>false</code> otherwise. - */ - public static final void setEnabled(Control control, boolean enabled) { - if (control != null && !control.isDisposed()) { - control.setEnabled(enabled); - } - } - - /** - * Returns the enabled state of the given control. The method returns always <code>true</code> - * in case the given control is <code>null</code> or disposed. - * - * @param control The control to get the enabled state for. - * @return <code>true</code> if the control is enabled, <code>false</code> otherwise. - */ - public static final boolean isEnabled(Control control) { - if (control != null && !control.isDisposed()) { - return control.isEnabled(); - } - return true; - } - - /** - * Sets the visible state of the given control. The state will be applied in - * case the given control is not <code>null</code> and not disposed. - * - * @param control The control to set the visible state for. - * @param visible <code>True</code> to set the control visible, <code>false</code> otherwise. - */ - public static final void setVisible(Control control, boolean visible) { - if (control != null && !control.isDisposed()) { - control.setVisible(visible); - } - } - - /** - * Returns the visible state of the given control. The method returns always - * <code>true</code> in case the given control is <code>null</code> or disposed. - * - * @param control The control to set the visible state for. - * @param visible <code>True</code> to set the control visible, <code>false</code> otherwise. - */ - public static final boolean isVisible(Control control) { - if (control != null && !control.isDisposed()) { - return control.getVisible(); - } - return true; - } - - /** - * Returns the item count of the specified control. The method will return <code>0</code> - * in case the control is <code>null</code> or has been already disposed or does not - * support items. - * - * @param control The control to get the item count for. - * @return The number of items within the control or <code>-1</code>. - */ - public static final int getItemCount(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof Combo) { - return ((Combo)control).getItemCount(); - } - if (control instanceof List) { - return ((List)control).getItemCount(); - } - } - return -1; - } - - /** - * Sets the specified items to the specified control. - * - * @param control The control to set the items to. - * @param items The array of items to set. - */ - public static final void setItems(Control control, String[] items) { - if (control != null && !control.isDisposed() && items != null) { - if (control instanceof Combo) { - ((Combo)control).setItems(items); - } - else if (control instanceof List) { - ((List)control).setItems(items); - } - } - } - - /** - * Returns the items of the specified control. The method will return an empty array - * in case the control is <code>null</code> or has been already disposed or does not - * support items. - * - * @param control The control to get the items from. - * @return The array items or and empty array. - */ - public static final String[] getItems(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof Combo) { - return ((Combo)control).getItems(); - } - if (control instanceof List) { - return ((List)control).getItems(); - } - } - return new String[0]; - } - - /** - * Sets the text of the specified item of the specified control. - * - * @param control The control to set the item text. - * @param index The index of the item to change. - * @param value The new item text to apply. - */ - public static final void setItem(Control control, int index, String value) { - if (control != null && !control.isDisposed() && value != null) { - // The index must be within valid range - if (index >= 0 && index < getItemCount(control)) { - String trimmedValue = value.trim(); - - // Avoid triggering attached listeners if the value has not changed. - String oldValue = getItem(control, index); - if (!trimmedValue.equals(oldValue)) { - if (control instanceof Combo) { - ((Combo)control).setItem(index, trimmedValue); - } - if (control instanceof List) { - ((List)control).setItem(index, trimmedValue); - } - } - } - } - } - - /** - * Returns the text of the item at the specified index of the specified control. - * - * @param control The control to query the item text from. - * @param index The index of the item to query. - * @return The item text or <code>null</code>. - */ - public static final String getItem(Control control, int index) { - if (control != null && !control.isDisposed()) { - // The index must be within valid range - if (index >= 0 && index < getItemCount(control)) { - if (control instanceof Combo) { - return ((Combo)control).getItem(index).trim(); - } - if (control instanceof List) { - return ((List)control).getItem(index).trim(); - } - } - } - return null; - } - - /** - * Returns the selected item index of the specified control. The method will return <code>-1</code> in case - * the control is <code>null</code> or has been already disposed or does not support selections. - * - * @param control The control to get the selected item index for. - * @return The index of the selected item within the control or <code>-1</code>. - */ - public static final int getSelectionIndex(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof Combo) { - return ((Combo)control).getSelectionIndex(); - } - if (control instanceof List) { - return ((List)control).getSelectionIndex(); - } - if (control instanceof Table) { - return ((Table)control).getSelectionIndex(); - } - } - return -1; - } - - /** - * Returns the selected item count of the specified control. The method will return <code>-1</code> in case - * the control is <code>null</code> or has been already disposed or does not support selections. - * - * @param control The control to get the selected item count for. - * @return The number of selected items within the control or <code>-1</code>. - */ - public static final int getSelectionCount(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof List) { - return ((List)control).getSelectionCount(); - } - if (control instanceof Table) { - return ((Table)control).getSelectionCount(); - } - if (control instanceof Tree) { - return ((Tree)control).getSelectionCount(); - } - } - return -1; - } - - /** - * Removes all items of the specified control. - * - * @param control The control to remove all items from. - */ - public static final void removeAll(Control control) { - if (control != null && !control.isDisposed()) { - if (control instanceof Combo) { - ((Combo)control).removeAll(); - } - if (control instanceof List) { - ((List)control).removeAll(); - } - if (control instanceof Table) { - ((Table)control).removeAll(); - } - if (control instanceof Tree) { - ((Tree)control).removeAll(); - } - } - } - - /** - * Returns the index of the given item for the specified control. The method will return - * <code>-1</code> in case the control is <code>null</code> or has been already disposed - * or does not support items. - * - * @param control The control to lookup the item index. - * @param item The item to lookup the index for. - * @return The item index if found or <code>-1</code>. - */ - public static final int indexOf(Control control, String item) { - if (control != null && !control.isDisposed() && item != null) { - if (control instanceof Combo) { - return ((Combo)control).indexOf(item); - } - if (control instanceof List) { - return ((List)control).indexOf(item); - } - } - return -1; - } - - /** - * Selects the item with the given item index for the specified control. The method will - * return immediately in case the control is <code>null</code> or has been already - * disposed or does not support items. - * - * @param control The control to select the given item. - * @param item The item to select. - */ - public static final void select(Control control, int index) { - if (control != null && !control.isDisposed()) { - if (index >= 0 && index < getItemCount(control)) { - if (control instanceof Combo) { - ((Combo)control).select(index); - } - if (control instanceof List) { - ((List)control).select(index); - } - } - } - return; - } - - /** - * Returns the buttons selection state. - * - * @param button The button to query the selection state for. - * @return <code>true</code> if the button specified is not <code>null</code> nor disposed and selected, <code>false</code> otherwise. - */ - public static final boolean getSelection(Button button) { - if (button != null && !button.isDisposed()) { - return button.getSelection(); - } - return false; - } - - /** - * Sets the buttons selection state to the given state. - * - * @param button The button to set the selection state for. - * @param selected The button selection state to set. - */ - public static final void setSelection(Button button, boolean selected) { - if (button != null && !button.isDisposed()) { - button.setSelection(selected); - } - } - - /** - * Returns the number of pixels corresponding to the height of the given - * number of characters. - * <p> - * This methods uses the static {@link Dialog#convertHeightInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)} - * method for calculation. - * <p> - * @param chars The number of characters - * @return The corresponding height in pixels - */ - public static int convertHeightInCharsToPixels(Control control, int chars) { - int height = 0; - if (control != null && !control.isDisposed()) { - GC gc = new GC(control); - gc.setFont(JFaceResources.getDialogFont()); - height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), chars); - gc.dispose(); - } - - return height; - } - - /** - * Returns the number of pixels corresponding to the width of the given - * number of characters. - * <p> - * This methods uses the static {@link Dialog#convertWidthInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)} - * method for calculation. - * <p> - * @param chars The number of characters - * @return The corresponding width in pixels - */ - public static int convertWidthInCharsToPixels(Control control, int chars) { - int width = 0; - if (control != null && !control.isDisposed()) { - GC gc = new GC(control); - gc.setFont(JFaceResources.getDialogFont()); - width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), chars); - gc.dispose(); - } - - return width; - } - - /** - * Sets the focus to the given control. - * - * @param control The control to set the focus to. - * @return <code>True</code> if the control got the focus, <code>false</code> otherwise. - */ - public static boolean setFocus(Control control) { - if (control != null && !control.isDisposed()) { - return control.setFocus(); - } - return false; - } - - /** - * Sets the given color as control foreground. - * - * @param control The control. - * @param color The color. - */ - public static void setForeground(Control control, Color color) { - if (control != null && !control.isDisposed() && color != null) { - control.setForeground(color); - } - } - - /** - * Sets the given color as control background. - * - * @param control The control. - * @param color The color. - */ - public static void setBackground(Control control, Color color) { - if (control != null && !control.isDisposed() && color != null) { - control.setBackground(color); - } - } - - /** - * Sets the given image as control background image. - * - * @param control The control. - * @param image The image. - */ - public static void setBackgroundImage(Control control, Image image) { - if (control != null && !control.isDisposed() && image != null) { - control.setBackgroundImage(image); - } - } - - /* -------------------------------------------------------------------- - * - * Generate system specific checkbox images. - * - * -------------------------------------------------------------------- */ - - private static final String CHECKED = "CHECKED"; //$NON-NLS-1$ - private static final String UNCHECKED = "UNCHECKED"; //$NON-NLS-1$ - private static final String GRAYED = "GRAYED"; //$NON-NLS-1$ - private static final String ENABLED = "ENABLED"; //$NON-NLS-1$ - private static final String DISABLED = "DISABLED"; //$NON-NLS-1$ - - private static Image makeShot(Shell shell, boolean checked, boolean grayed, boolean enabled) { - shell = new Shell(shell, SWT.NO_FOCUS | SWT.NO_TRIM); - - Color greenScreen = new Color(shell.getDisplay(), 222, 223, 224); - shell.setBackground(greenScreen); - - Button button = new Button(shell, SWT.CHECK); - button.setBackground(greenScreen); - button.setSelection(grayed || checked); - button.setEnabled(enabled); - button.setGrayed(grayed); - - button.setLocation(0, 0); - Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); - - button.setSize(bsize); - shell.setSize(bsize); - - shell.open(); - GC gc = new GC(shell); - Image image = new Image(shell.getDisplay(), bsize.x, bsize.y); - gc.copyArea(image, 0, 0); - gc.dispose(); - - ImageData imageData = image.getImageData(); - imageData.transparentPixel = imageData.palette.getPixel(greenScreen - .getRGB()); - image = new Image(shell.getDisplay(), imageData); - shell.close(); - - return image; - } - - public static synchronized Image getCheckBoxImage(boolean checked, boolean grayed, boolean enabled) { - String key = (SWTControlUtil.class.getName() + "_" + //$NON-NLS-1$ - ((checked || grayed) ? CHECKED : UNCHECKED) + "_" + //$NON-NLS-1$ - (grayed ? GRAYED + "_" : "") + //$NON-NLS-1$ //$NON-NLS-2$ - (enabled ? ENABLED : DISABLED)); - - Image image = JFaceResources.getImageRegistry().get(key); - try { - if (image == null || image.getImageData().data == null) { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - image = makeShot(shell, checked||grayed, grayed, enabled); - if (image != null && image.getImageData().data != null) { - JFaceResources.getImageRegistry().put(key, image); - } - } - } - catch (Exception e) { - } - - return image; - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/activator/UIPlugin.java deleted file mode 100644 index 5afdc2db5..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/activator/UIPlugin.java +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
- * This program and the accompanying materials are made available under the terms
- * of the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tm.te.ui.swt.activator;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class UIPlugin extends AbstractUIPlugin {
- // The shared instance
- private static UIPlugin plugin;
-
- /**
- * The constructor
- */
- public UIPlugin() {
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static UIPlugin getDefault() {
- return plugin;
- }
-
- /**
- * Convenience method which returns the unique identifier of this plugin.
- */
- public static String getUniqueIdentifier() {
- if (getDefault() != null && getDefault().getBundle() != null) {
- return getDefault().getBundle().getSymbolicName();
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCellPaintListener.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCellPaintListener.java deleted file mode 100644 index cf180d483..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCellPaintListener.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * AbstractCellPaintListener.java - * Created on Aug 21, 2011 - * - * Copyright (c) 2011 Wind River Systems, Inc. - * - * The right to copy, distribute, modify, or otherwise make use - * of this software may be licensed only pursuant to the terms - * of an applicable Wind River license agreement. - */ -package org.eclipse.tm.te.ui.swt.listener; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.swt.widgets.Widget; - -/** - * Abstract cell paint listener implementation - */ -public abstract class AbstractCellPaintListener implements Listener { - - private final int[] columns; - - /** - * Constructor. - * @param colums The valid columns. - * @param widget The widget. - */ - public AbstractCellPaintListener(Widget widget, int... columns) { - this.columns = columns; - register(widget); - } - - /** - * Add this listener to the widget. - * @param widget The widget. - */ - protected void register(Widget widget) { - if (widget != null && !widget.isDisposed()) { - widget.addListener(SWT.MeasureItem, this); - widget.addListener(SWT.PaintItem, this); - widget.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent e) { - deregister(e.widget); - } - }); - } - } - - /** - * Remove this listener from the widget. - * @param widget The widget. - */ - protected void deregister(Widget widget) { - if (widget != null) { - widget.removeListener(SWT.MeasureItem, this); - widget.removeListener(SWT.PaintItem, this); - } - } - - /* (non-Javadoc) - * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) - */ - @Override - public void handleEvent(Event event) { - // Check if the event type is handled. - if (!isHandledEventType(event.type)) { - return; - } - - // We can paint something only if the item is available - if (event.item instanceof Item) { - // Check if the table item is valid - if (isValid(event)) { - // Forward to the event type specific handler methods - switch (event.type) { - case SWT.MeasureItem: - doHandleMeasureItemEvent(event); - break; - case SWT.PaintItem: - doHandlePaintItemEvent(event); - break; - } - } - } - } - - /** - * Returns if or if not the given event type is handled by this handler. - * <p> - * The default implementation accepts {@link SWT#MeasureItem} and {@link SWT#PaintItem}. - * - * @param type The event type. - * @return <code>True</code> if the event type is handled by this handler, <code>false</code> otherwise. - */ - protected boolean isHandledEventType(int type) { - return SWT.MeasureItem == type || SWT.PaintItem == type; - } - - /** - * Handle the measure item event. - * @param event The event. - */ - protected void doHandleMeasureItemEvent(Event event) { - Assert.isNotNull(event); - - // Get the image to draw. - Image image = getImageToDraw((Item)event.item, event.index); - // We have to measure anything only if the returned image is not null. - if (image != null) { - // Width must be minimum image width + 1 pixels at each side - event.width = Math.max(event.width, image.getImageData().width + 2); - // Height must be minimum image width + 1 pixels at each side - event.height = Math.max(event.height, image.getImageData().height + 2); - } - } - - /** - * Handle the paint item event. - * @param event The event. - */ - protected void doHandlePaintItemEvent(Event event) { - Assert.isNotNull(event); - - // Get the image to draw. - Image image = getImageToDraw((Item)event.item, event.index); - // We have to draw anything only if the returned image is not null. - if (image != null) { - Point point = getPaintOrigin(event, image); - // Paint the image - event.gc.drawImage(image, point.x, point.y); - } - } - - /** - * Get the origin where the image should be painted. - * @param event The event. - * @param image The image. - * @return The origin. - */ - protected abstract Point getPaintOrigin(Event event, Image image); - - /** - * Get the width of the widget where the image to draw into. - * @param event The event. - * @return The width. - */ - protected int getWidgetWidth(Event event) { - if (event.widget instanceof Table) { - TableColumn column = ((Table)event.widget).getColumn(event.index); - return column.getWidth(); - } - else if (event.widget instanceof Tree) { - TreeColumn column = ((Tree)event.widget).getColumn(event.index); - return column.getWidth(); - } - return event.width; - } - - /** - * Get the image to draw - * @param item The item to draw the image for. - * @param columnIndex The column index. - * @return The image or <code>null</code>. - */ - protected abstract Image getImageToDraw(Item item, int columnIndex); - - /** - * Returns if or if not the given events data is valid. - * Subclass implementers may check if the associated data object - * is matching and expected data type. - * - * @param event The event. Must not be <code>null</code>. - * @return <code>True</code> if the events data is valid, <code>false</code> otherwise. - */ - protected boolean isValid(Event event) { - return (event.item != null && isPaintImageInColumn(event.index) && - ((event.widget instanceof Table && event.item instanceof TableItem) || - (event.widget instanceof Tree && event.item instanceof TreeItem))); - } - - /** - * Returns if or if not the managed image shall be painted to the - * given column. - * - * @param columnIndex The column index of the current column. - * @return <code>True</code> if the image shall be painted, <code>false</code> otherwise. - */ - protected boolean isPaintImageInColumn(int columnIndex) { - for (int col : columns) { - if (col == columnIndex) { - return true; - } - } - return false; - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCheckBoxCellPaintListener.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCheckBoxCellPaintListener.java deleted file mode 100644 index 23f6902aa..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractCheckBoxCellPaintListener.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * AbstractCheckBoxCellPaintListener.java - * Created on Aug 21, 2011 - * - * Copyright (c) 2011 Wind River Systems, Inc. - * - * The right to copy, distribute, modify, or otherwise make use - * of this software may be licensed only pursuant to the terms - * of an applicable Wind River license agreement. - */ -package org.eclipse.tm.te.ui.swt.listener; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.tm.te.ui.swt.SWTControlUtil; - -/** - * Abstract check box cell paint listener implementation. - */ -public abstract class AbstractCheckBoxCellPaintListener extends AbstractCellPaintListener { - - private static final int ENABLED = 1; - private static final int CHECKED = 2; - private static final int TRISTATE = 4; - - protected static final int STATE_NONE = -1; - protected static final int STATE_ENABLED_CHECKED = ENABLED | CHECKED; - protected static final int STATE_ENABLED_UNCHECKED = ENABLED; - protected static final int STATE_ENABLED_TRISTATE = ENABLED | TRISTATE; - protected static final int STATE_DISABLED_CHECKED = CHECKED; - protected static final int STATE_DISABLED_UNCHECKED = 0; - protected static final int STATE_DISABLED_TRISTATE = TRISTATE; - - /** - * Constructor. - * - * @param columns The valid columns. - * @param widget The widget. - */ - public AbstractCheckBoxCellPaintListener(Widget widget, int... columns) { - super(widget, columns); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.ui.swt.listener.AbstractCellPaintListener#getPaintOrigin(org.eclipse.swt.widgets.Event, org.eclipse.swt.graphics.Image) - */ - @Override - protected Point getPaintOrigin(Event event, Image image) { - // Determine host platform - boolean isWindowsHost = System.getProperty("os.name","").toLowerCase().startsWith("windows"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // Center the image horizontally within the column - int x = event.x + (getWidgetWidth(event)/2 - image.getImageData().width / 2); - // Center the image vertically within the column - int y = isWindowsHost ? event.y : event.y + event.height - (image.getImageData().height + 4); - return new Point(x, y); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.ui.swt.listener.AbstractCellPaintListener#getImageToDraw(org.eclipse.swt.widgets.Item, int) - */ - @Override - protected Image getImageToDraw(Item item, int columnIndex) { - Assert.isNotNull(item); - - // If the image shall be painted to the current column - if (isPaintImageInColumn(columnIndex)) { - // Check which image to paint - int state = getCheckBoxState(item.getData(), columnIndex); - if (state >= 0) { - return SWTControlUtil.getCheckBoxImage((state & CHECKED) > 0, (state & TRISTATE) > 0, (state & ENABLED) > 0); - } - } - - return null; - } - - /** - * Returns the state for the check box. - * - * @param data The associated event data or <code>null</code>: - * @param columnIndex The column index of the current column. - * - * @return The state for the check box. - */ - protected abstract int getCheckBoxState(Object data, int columnIndex); - -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractDecorationCellPaintListener.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractDecorationCellPaintListener.java deleted file mode 100644 index 84fac2862..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/listener/AbstractDecorationCellPaintListener.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * AbstractDecorationCellPaintListener.java - * Created on Aug 21, 2011 - * - * Copyright (c) 2011 Wind River Systems, Inc. - * - * The right to copy, distribute, modify, or otherwise make use - * of this software may be licensed only pursuant to the terms - * of an applicable Wind River license agreement. - */ -package org.eclipse.tm.te.ui.swt.listener; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.fieldassist.FieldDecoration; -import org.eclipse.jface.fieldassist.FieldDecorationRegistry; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Widget; - -/** - * Abstract decoration cell paint listener implementation - */ -public abstract class AbstractDecorationCellPaintListener extends AbstractCellPaintListener { - - public static final int STATE_NONE = IMessageProvider.NONE; - public static final int STATE_INFO = IMessageProvider.INFORMATION; - public static final int STATE_WARNING = IMessageProvider.WARNING; - public static final int STATE_ERROR = IMessageProvider.ERROR; - - /** - * Constructor. - * @param colums The valid columns. - * @param widget The widget. - */ - public AbstractDecorationCellPaintListener(Widget widget, int... columns) { - super(widget, columns); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.ui.swt.listener.AbstractCellPaintListener#getPaintOrigin(org.eclipse.swt.widgets.Event, org.eclipse.swt.graphics.Image) - */ - @Override - protected Point getPaintOrigin(Event event, Image image) { - return new Point(event.x, event.y); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.ui.swt.listener.AbstractCellPaintListener#getImageToDraw(org.eclipse.swt.widgets.Item, int) - */ - @Override - protected Image getImageToDraw(Item item, int columnIndex) { - Assert.isNotNull(item); - - // If the image shall be painted to the current column - if (isPaintImageInColumn(columnIndex)) { - // Check which image to paint - int state = getDecorationState(item.getData(), columnIndex); - if (state >= 0) { - String decorationId = null; - switch (state) { - case STATE_INFO: - decorationId = FieldDecorationRegistry.DEC_INFORMATION; - break; - case STATE_WARNING: - decorationId = FieldDecorationRegistry.DEC_WARNING; - break; - case STATE_ERROR: - decorationId = FieldDecorationRegistry.DEC_ERROR; - break; - } - if (decorationId != null) { - // Get the field decoration - FieldDecoration fieldDeco = FieldDecorationRegistry.getDefault().getFieldDecoration(decorationId); - if (fieldDeco != null) { - return fieldDeco.getImage(); - } - } - } - } - - return null; - } - - /** - * Returns the state for the decoration. - * - * @param data The associated event data or <code>null</code>: - * @param columnIndex The column index of the current column. - * - * @return The state for the decoration. - */ - protected abstract int getDecorationState(Object data, int columnIndex); - -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.java deleted file mode 100644 index a193fc3df..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.ui.swt.nls; - -import java.lang.reflect.Field; - -import org.eclipse.osgi.util.NLS; - -/** - * Common SWT and JFace Helper plug-in externalized strings management. - */ -public class Messages extends NLS { - - // The plug-in resource bundle name - private static final String BUNDLE_NAME = "org.eclipse.tm.te.ui.swt.nls.Messages"; //$NON-NLS-1$ - - /** - * Static constructor. - */ - static { - // Load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - /** - * Returns if or if not this NLS manager contains a constant for - * the given externalized strings key. - * - * @param key The externalized strings key or <code>null</code>. - * @return <code>True</code> if a constant for the given key exists, <code>false</code> otherwise. - */ - public static boolean hasString(String key) { - if (key != null) { - try { - Field field = Messages.class.getDeclaredField(key); - return field != null; - } catch (NoSuchFieldException e) { /* ignored on purpose */ } - } - - return false; - } - - /** - * Returns the corresponding string for the given externalized strings - * key or <code>null</code> if the key does not exist. - * - * @param key The externalized strings key or <code>null</code>. - * @return The corresponding string or <code>null</code>. - */ - public static String getString(String key) { - if (key != null) { - try { - Field field = Messages.class.getDeclaredField(key); - if (field != null) { - return (String)field.get(null); - } - } catch (Exception e) { /* ignored on purpose */ } - } - - return null; - } - - // **** Declare externalized string id's down here ***** - - public static String NoteCompositeHelper_note_label; - - public static String OptionalMessageDialog_doNotShowAgain_label; - public static String OptionalMessageDialog_rememberMyDecision_label; -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.properties deleted file mode 100644 index bc4923e3d..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/nls/Messages.properties +++ /dev/null @@ -1,9 +0,0 @@ -# -# org.eclipse.tm.te.ui.swt -# Externalized Strings. -# - -NoteCompositeHelper_note_label=Note: - -OptionalMessageDialog_doNotShowAgain_label=Do not show again -OptionalMessageDialog_rememberMyDecision_label=Remember my decision diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/widgets/NoteCompositeHelper.java b/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/widgets/NoteCompositeHelper.java deleted file mode 100644 index d6f6deaa7..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.swt/src/org/eclipse/tm/te/ui/swt/widgets/NoteCompositeHelper.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.te.ui.swt.widgets; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Font; -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.Label; -import org.eclipse.tm.te.ui.swt.SWTControlUtil; -import org.eclipse.tm.te.ui.swt.nls.Messages; - -/** - * A helper class to create a composite with a highlighted note - * entry and a message text. - */ -public class NoteCompositeHelper { - - /** - * The common label text to show on a note. Defaults to "Note:". - */ - public static final String NOTE_LABEL = Messages.NoteCompositeHelper_note_label; - - private static class NoteComposite extends Composite { - - public NoteComposite(Composite parent, int style) { - super(parent, style); - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - Control[] childs = getChildren(); - for (int iChild = 0; iChild < childs.length; iChild++) { - Control child = childs[iChild]; - child.setEnabled(enabled); - } - } - } - - /** - * Creates a composite with a highlighted Note entry and a message text. - * This is designed to take up the full width of the page. - * - * @see PreferencePage#createNoteComposite, this is a plain copy of that! - * @param font - * the font to use - * @param composite - * the parent composite - * @param title - * the title of the note - * @param message - * the message for the note - * @return the composite for the note - */ - public static Composite createNoteComposite(Font font, Composite composite, String title, String message) { - Composite messageComposite = new NoteComposite(composite, SWT.NONE); - - GridLayout messageLayout = new GridLayout(); - messageLayout.numColumns = 2; - messageLayout.marginWidth = 0; - messageLayout.marginHeight = 0; - messageComposite.setLayout(messageLayout); - - GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - if (composite.getLayout() instanceof GridLayout) { - layoutData.horizontalSpan = ((GridLayout) composite.getLayout()).numColumns; - } - messageComposite.setLayoutData(layoutData); - messageComposite.setFont(font); - - final Label noteLabel = new Label(messageComposite, SWT.BOLD); - noteLabel.setText(title); - noteLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); - noteLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - - final IPropertyChangeListener fontListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - // Note: This is actually wrong but the same as in platforms - // PreferencePage - if (JFaceResources.BANNER_FONT.equals(event.getProperty())) { - noteLabel.setFont(JFaceResources.getFont(JFaceResources.BANNER_FONT)); - } - } - }; - JFaceResources.getFontRegistry().addListener(fontListener); - noteLabel.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent event) { - JFaceResources.getFontRegistry().removeListener(fontListener); - } - }); - - Label messageLabel = new Label(messageComposite, SWT.WRAP); - messageLabel.setText(message); - messageLabel.setFont(font); - - /** - * Set the controls style to FILL_HORIZONTAL making it multi-line if - * needed - */ - layoutData = new GridData(GridData.FILL_HORIZONTAL); - layoutData.widthHint = SWTControlUtil.convertWidthInCharsToPixels(messageLabel, 65); - messageLabel.setLayoutData(layoutData); - - return messageComposite; - } - - /** - * change the text of the second label - * - * @param messageComposite - * the NoteComposite that gets returned from createNoteComposite - * @param msg - * the new text - */ - public static void setMessage(Composite messageComposite, String msg) { - if (messageComposite instanceof NoteComposite) { - Control[] children = messageComposite.getChildren(); - if (children.length == 2) { - Control c = children[1]; - if (c instanceof Label) { - ((Label) c).setText(msg); - messageComposite.pack(); - } - } - } - } -} |