001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.designstudio.editors.actionsequence.pages.parameters;
014:
015: import java.util.ArrayList;
016: import java.util.Arrays;
017: import java.util.Iterator;
018:
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.events.SelectionEvent;
021: import org.eclipse.swt.events.SelectionListener;
022: import org.eclipse.swt.graphics.Image;
023: import org.eclipse.swt.graphics.Point;
024: import org.eclipse.swt.graphics.Rectangle;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Menu;
027: import org.eclipse.swt.widgets.MenuItem;
028: import org.eclipse.swt.widgets.ToolBar;
029: import org.eclipse.swt.widgets.ToolItem;
030: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
031: import org.pentaho.designstudio.editors.actionsequence.preferences.InputSourcesEditor;
032: import org.pentaho.designstudio.editors.actionsequence.preferences.PreferenceConstants;
033: import org.pentaho.designstudio.messages.Messages;
034:
035: public class OutputDestToolbar {
036:
037: static final Image ADD_ICON = ActionSequenceEditorPlugin
038: .getImageDescriptor(
039: Messages
040: .getString("ActionsMasterDetailBlock.ICON_ADD_ACTION")).createImage(); //$NON-NLS-1$
041:
042: static final Image REMOVE_ICON = ActionSequenceEditorPlugin
043: .getImageDescriptor(
044: Messages
045: .getString("ActionsMasterDetailBlock.ICON_REMOVE_ACTION")).createImage(); //$NON-NLS-1$
046:
047: static final Image MOVE_UP_ICON = ActionSequenceEditorPlugin
048: .getImageDescriptor(
049: Messages
050: .getString("ActionsMasterDetailBlock.ICON_MOVE_UP")).createImage(); //$NON-NLS-1$
051:
052: static final Image MOVE_DOWN_ICON = ActionSequenceEditorPlugin
053: .getImageDescriptor(
054: Messages
055: .getString("ActionsMasterDetailBlock.ICON_MOVE_DOWN")).createImage(); //$NON-NLS-1$
056:
057: OutputDestViewer outputDestViewer;
058: ToolBar toolBar;
059:
060: public OutputDestToolbar(Composite parent, OutputDestViewer viewer) {
061: outputDestViewer = viewer;
062:
063: toolBar = new ToolBar(parent, SWT.FLAT);
064:
065: ToolItem toolItem = new ToolItem(toolBar, SWT.DROP_DOWN);
066: toolItem.setImage(ADD_ICON);
067: toolItem.setToolTipText(Messages
068: .getString("OutputDestCoolbar.ADD_DESTINATION")); //$NON-NLS-1$
069: final Menu addMenu = new Menu(toolBar.getShell(), SWT.POP_UP);
070: toolItem.addSelectionListener(new SelectionListener() {
071: public void widgetDefaultSelected(SelectionEvent e) {
072: }
073:
074: public void widgetSelected(SelectionEvent e) {
075: ToolItem item = (ToolItem) e.widget;
076: Rectangle rectangle = item.getBounds();
077: Point pt = item.getParent().toDisplay(
078: new Point(rectangle.x, rectangle.y));
079:
080: MenuItem[] menuItems = addMenu.getItems();
081: for (int i = 0; i < menuItems.length; i++) {
082: menuItems[i].dispose();
083: }
084:
085: ArrayList destinations = new ArrayList();
086: destinations
087: .addAll(Arrays
088: .asList(InputSourcesEditor
089: .parsePrefsString(ActionSequenceEditorPlugin
090: .getDefault()
091: .getPluginPreferences()
092: .getString(
093: PreferenceConstants.OUTPUT_DEST))));
094:
095: for (Iterator iter = destinations.iterator(); iter
096: .hasNext();) {
097: MenuItem menuItem = new MenuItem(addMenu, SWT.NONE);
098: menuItem.setText(iter.next().toString());
099: menuItem
100: .addSelectionListener(new SelectionListener() {
101: public void widgetDefaultSelected(
102: SelectionEvent e) {
103: }
104:
105: public void widgetSelected(
106: SelectionEvent e) {
107: outputDestViewer
108: .addDestination(((MenuItem) e
109: .getSource())
110: .getText());
111: }
112: });
113: }
114:
115: addMenu.setLocation(pt.x, pt.y + rectangle.height);
116: addMenu.setVisible(true);
117: }
118:
119: });
120:
121: toolItem = new ToolItem(toolBar, SWT.NULL);
122: toolItem.setImage(REMOVE_ICON);
123: toolItem.setToolTipText(Messages
124: .getString("OutputDestCoolbar.REMOVE_DESTINATION")); //$NON-NLS-1$
125: toolItem.addSelectionListener(new SelectionListener() {
126: public void widgetDefaultSelected(SelectionEvent e) {
127: }
128:
129: public void widgetSelected(SelectionEvent e) {
130: Point[] selection = outputDestViewer.getCellSelection();
131: outputDestViewer.deleteRow(selection[0].y);
132: }
133:
134: });
135: }
136:
137: public ToolBar getControl() {
138: return toolBar;
139: }
140:
141: }
|