Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.photran.internal.ui.properties; |
12 |
|
13 |
import java.util.Arrays; |
14 |
|
15 |
import org.eclipse.jface.preference.ListEditor; |
16 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
17 |
import org.eclipse.jface.viewers.LabelProvider; |
18 |
import org.eclipse.photran.internal.core.properties.SearchPathProperties; |
19 |
import org.eclipse.swt.SWT; |
20 |
import org.eclipse.swt.widgets.Composite; |
21 |
import org.eclipse.ui.dialogs.ListDialog; |
22 |
|
23 |
/** |
24 |
* A field editor to edit which file types to send to the C Preprocessor. |
25 |
* |
26 |
* @author Jeff Overbey, Kurt Hendle |
27 |
*/ |
28 |
public class CPPFileTypeEditor extends ListEditor |
29 |
{ |
30 |
private String[] fileTypes; |
31 |
/** |
32 |
* The special label text for chooser, |
33 |
* or <code>null</code> if none. |
34 |
*/ |
35 |
private String fileTypeInputLabelText; |
36 |
|
37 |
/** |
38 |
* Creates a new path field editor |
39 |
*/ |
40 |
protected CPPFileTypeEditor() |
41 |
{ |
42 |
} |
43 |
|
44 |
/** |
45 |
* Creates a CPP file type chooser. |
46 |
* |
47 |
* @param name the name of the preference this field editor works on |
48 |
* @param labelText the label text of the field editor |
49 |
* @param fileTypes an array of file types to be available in the list |
50 |
* @param typeChooserText the label text displayed for the directory chooser |
51 |
* @param parent the parent of the field editor's control |
52 |
*/ |
53 |
public CPPFileTypeEditor(String name, String labelText, String[] fileTypes, String typeChooserText, Composite parent) |
54 |
{ |
55 |
parent = new Composite(parent, SWT.NONE); |
56 |
init(name, labelText); |
57 |
this.fileTypes = fileTypes; |
58 |
this.fileTypeInputLabelText = typeChooserText; |
59 |
createControl(parent); |
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 |
{ |
68 |
//set up the list dialog box |
69 |
ListDialog dialog = new ListDialog(getShell()); |
70 |
dialog.setInput(fileTypes); |
71 |
dialog.setContentProvider(new ArrayContentProvider()); |
72 |
dialog.setLabelProvider(new LabelProvider()); |
73 |
dialog.setMessage(fileTypeInputLabelText); |
74 |
|
75 |
if (dialog.open() == ListDialog.OK) |
76 |
{ |
77 |
//result is returned as an object array, must convert it to string and return string |
78 |
Object[] selection = dialog.getResult(); |
79 |
String [] type = Arrays.asList(selection).toArray(new String[selection.length]); |
80 |
return type[0]; |
81 |
} |
82 |
|
83 |
return null; |
84 |
} |
85 |
|
86 |
@Override |
87 |
protected String createList(String[] items) |
88 |
{ |
89 |
return SearchPathProperties.createList(items); |
90 |
} |
91 |
|
92 |
@Override |
93 |
protected String[] parseString(String stringList) |
94 |
{ |
95 |
return SearchPathProperties.parseString(stringList); |
96 |
} |
97 |
} |