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.jface.dialogs.MessageDialog;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.events.SelectionListener;
023: import org.eclipse.swt.graphics.Image;
024: import org.eclipse.swt.graphics.Point;
025: import org.eclipse.swt.graphics.Rectangle;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Menu;
028: import org.eclipse.swt.widgets.MenuItem;
029: import org.eclipse.swt.widgets.ToolBar;
030: import org.eclipse.swt.widgets.ToolItem;
031: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
032: import org.pentaho.designstudio.editors.actionsequence.preferences.InputSourcesEditor;
033: import org.pentaho.designstudio.editors.actionsequence.preferences.PreferenceConstants;
034: import org.pentaho.designstudio.messages.Messages;
035:
036: public class InputSrcToolbar {
037:
038: static final Image ADD_ICON = ActionSequenceEditorPlugin
039: .getImageDescriptor(
040: Messages
041: .getString("ActionsMasterDetailBlock.ICON_ADD_ACTION")).createImage(); //$NON-NLS-1$
042:
043: static final Image REMOVE_ICON = ActionSequenceEditorPlugin
044: .getImageDescriptor(
045: Messages
046: .getString("ActionsMasterDetailBlock.ICON_REMOVE_ACTION")).createImage(); //$NON-NLS-1$
047:
048: static final Image MOVE_UP_ICON = ActionSequenceEditorPlugin
049: .getImageDescriptor(
050: Messages
051: .getString("ActionsMasterDetailBlock.ICON_MOVE_UP")).createImage(); //$NON-NLS-1$
052:
053: static final Image MOVE_DOWN_ICON = ActionSequenceEditorPlugin
054: .getImageDescriptor(
055: Messages
056: .getString("ActionsMasterDetailBlock.ICON_MOVE_DOWN")).createImage(); //$NON-NLS-1$
057:
058: InputSrcViewer inputSrcViewer;
059: ToolBar toolBar;
060:
061: public InputSrcToolbar(Composite parent, InputSrcViewer viewer) {
062: inputSrcViewer = viewer;
063:
064: toolBar = new ToolBar(parent, SWT.FLAT);
065: ToolItem toolItem = new ToolItem(toolBar, SWT.NULL);
066: toolItem.setImage(MOVE_DOWN_ICON);
067: toolItem.setToolTipText(Messages
068: .getString("InputSrcCoolbar.MOVE_ROW_UP")); //$NON-NLS-1$
069: toolItem.addSelectionListener(new SelectionListener() {
070: public void widgetDefaultSelected(SelectionEvent e) {
071: }
072:
073: public void widgetSelected(SelectionEvent e) {
074: Point[] selection = inputSrcViewer.getCellSelection();
075: if ((selection.length == 1)
076: && (selection[0].y < inputSrcViewer.getModel()
077: .getRowCount() - 1)) {
078: inputSrcViewer.moveRow(selection[0].y,
079: selection[0].y + 1);
080: inputSrcViewer.setSelection(selection[0].x,
081: selection[0].y + 1, true);
082: }
083: }
084: });
085:
086: toolItem = new ToolItem(toolBar, SWT.NULL);
087: toolItem.setImage(MOVE_UP_ICON);
088: toolItem.setToolTipText(Messages
089: .getString("InputSrcCoolbar.MOVE_ROW_DOWN")); //$NON-NLS-1$
090: toolItem.addSelectionListener(new SelectionListener() {
091: public void widgetDefaultSelected(SelectionEvent e) {
092: }
093:
094: public void widgetSelected(SelectionEvent e) {
095: Point[] selection = inputSrcViewer.getCellSelection();
096: if ((selection.length == 1)
097: && (selection[0].y > inputSrcViewer.getModel()
098: .getFixedHeaderRowCount())) {
099: inputSrcViewer.moveRow(selection[0].y,
100: selection[0].y - 1);
101: inputSrcViewer.setSelection(selection[0].x,
102: selection[0].y - 1, true);
103: }
104: }
105: });
106:
107: new ToolItem(toolBar, SWT.SEPARATOR);
108:
109: toolItem = new ToolItem(toolBar, SWT.DROP_DOWN);
110: toolItem.setImage(ADD_ICON);
111: toolItem.setToolTipText(Messages
112: .getString("InputSrcCoolbar.ADD_INPUT_SOURCE")); //$NON-NLS-1$
113: final Menu addMenu = new Menu(toolBar.getShell(), SWT.POP_UP);
114: toolItem.addSelectionListener(new SelectionListener() {
115: public void widgetDefaultSelected(SelectionEvent e) {
116: }
117:
118: public void widgetSelected(SelectionEvent e) {
119: ToolItem item = (ToolItem) e.widget;
120: Rectangle rectangle = item.getBounds();
121: Point pt = item.getParent().toDisplay(
122: new Point(rectangle.x, rectangle.y));
123:
124: MenuItem[] menuItems = addMenu.getItems();
125: for (int i = 0; i < menuItems.length; i++) {
126: menuItems[i].dispose();
127: }
128:
129: ArrayList sources = new ArrayList();
130: sources
131: .addAll(Arrays
132: .asList(InputSourcesEditor
133: .parsePrefsString(ActionSequenceEditorPlugin
134: .getDefault()
135: .getPluginPreferences()
136: .getString(
137: PreferenceConstants.INPUT_SOURCES))));
138:
139: for (Iterator iter = sources.iterator(); iter.hasNext();) {
140: MenuItem menuItem = new MenuItem(addMenu, SWT.NONE);
141: menuItem.setText(iter.next().toString());
142: menuItem
143: .addSelectionListener(new SelectionListener() {
144: public void widgetDefaultSelected(
145: SelectionEvent e) {
146: }
147:
148: public void widgetSelected(
149: SelectionEvent e) {
150: inputSrcViewer
151: .addSource(((MenuItem) e
152: .getSource())
153: .getText());
154: }
155: });
156: }
157: addMenu.setLocation(pt.x, pt.y + rectangle.height);
158: addMenu.setVisible(true);
159: }
160:
161: });
162:
163: toolItem = new ToolItem(toolBar, SWT.NULL);
164: toolItem.setImage(REMOVE_ICON);
165: toolItem.setToolTipText(Messages
166: .getString("InputSrcCoolbar.REMOVE_INPUT_SOURC")); //$NON-NLS-1$
167: toolItem.addSelectionListener(new SelectionListener() {
168: public void widgetDefaultSelected(SelectionEvent e) {
169: }
170:
171: public void widgetSelected(SelectionEvent e) {
172: Point[] selection = inputSrcViewer.getCellSelection();
173: inputSrcViewer.deleteRow(selection[0].y);
174: }
175:
176: });
177: }
178:
179: public ToolBar getControl() {
180: return toolBar;
181: }
182:
183: }
|