01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.pentaho.designstudio.editors.actionsequence.preferences;
11:
12: import java.util.ArrayList;
13: import java.util.StringTokenizer;
14:
15: import org.eclipse.jface.preference.ListEditor;
16: import org.eclipse.jface.window.Window;
17: import org.eclipse.swt.widgets.Composite;
18:
19: /**
20: * A field editor to edit directory paths.
21: */
22: public class InputSourcesEditor extends ListEditor {
23:
24: Composite parent;
25:
26: /**
27: * Creates a new path field editor
28: */
29: protected InputSourcesEditor() {
30: }
31:
32: /**
33: * Creates a path field editor.
34: *
35: * @param name the name of the preference this field editor works on
36: * @param labelText the label text of the field editor
37: * @param dirChooserLabelText the label text displayed for the directory chooser
38: * @param parent the parent of the field editor's control
39: */
40: public InputSourcesEditor(String name, String labelText,
41: Composite parent) {
42: init(name, labelText);
43: createControl(parent);
44: this .parent = parent;
45: }
46:
47: /* (non-Javadoc)
48: * Method declared on ListEditor.
49: * Creates a single string from the given array by separating each
50: * string with the appropriate OS-specific path separator.
51: */
52: protected String createList(String[] items) {
53: StringBuffer path = new StringBuffer("");//$NON-NLS-1$
54:
55: for (int i = 0; i < items.length; i++) {
56: path.append(items[i]);
57: path.append(":"); //$NON-NLS-1$
58: }
59: return path.toString();
60: }
61:
62: /* (non-Javadoc)
63: * Method declared on ListEditor.
64: * Creates a new path element by means of a directory dialog.
65: */
66: protected String getNewInputObject() {
67: String value = null;
68: InputSourceDialog inputDialog = new InputSourceDialog(
69: getShell(), getListControl(parent).getItems());
70: int result = inputDialog.open();
71: if (result == Window.OK) {
72: value = inputDialog.getValue();
73: if (value.trim().length() == 0) {
74: value = null;
75: }
76: }
77: return value;
78: }
79:
80: /*
81: * (non-Javadoc) Method declared on ListEditor.
82: */
83: protected String[] parseString(String stringList) {
84: return parsePrefsString(stringList);
85: }
86:
87: public static String[] parsePrefsString(String stringList) {
88: // StringTokenizer st = new StringTokenizer(stringList, File.pathSeparator
89: // + "\n\r");//$NON-NLS-1$
90: StringTokenizer st = new StringTokenizer(stringList, ":\n\r");//$NON-NLS-1$
91: ArrayList v = new ArrayList();
92: if (st != null) {
93: while (st.hasMoreElements()) {
94: v.add(st.nextElement());
95: }
96: }
97: return (String[]) v.toArray(new String[v.size()]);
98: }
99: }
|