KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > AntTypesPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.preferences;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.ant.core.AntCorePlugin;
19 import org.eclipse.ant.core.AntCorePreferences;
20 import org.eclipse.ant.core.Type;
21 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.jface.window.Window;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.TabFolder;
27 import org.eclipse.swt.widgets.TabItem;
28
29 /**
30  * Sub-page that allows the user to enter custom types
31  * to be used when running Ant build files.
32  */

33 public class AntTypesPage extends AntPage {
34     
35     /**
36      * Creates an instance.
37      */

38     public AntTypesPage(AntRuntimePreferencePage preferencePage) {
39         super(preferencePage);
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.ant.internal.ui.preferences.AntPage#addButtonsToButtonGroup(org.eclipse.swt.widgets.Composite)
44      */

45     protected void addButtonsToButtonGroup(Composite parent) {
46         createPushButton(parent, AntPreferencesMessages.AntTypesPage_2, ADD_BUTTON);
47         editButton = createPushButton(parent, AntPreferencesMessages.AntTypesPage_3, EDIT_BUTTON);
48         removeButton = createPushButton(parent, AntPreferencesMessages.AntTypesPage_1, REMOVE_BUTTON);
49     }
50     
51     /**
52      * Allows the user to enter a custom type.
53      */

54     protected void add() {
55         String JavaDoc title = AntPreferencesMessages.AntTypesPage_addTypeDialogTitle;
56         AddCustomDialog dialog = getCustomDialog(title, IAntUIHelpContextIds.ADD_TYPE_DIALOG);
57         if (dialog.open() == Window.CANCEL) {
58             return;
59         }
60
61         Type type = new Type();
62         type.setTypeName(dialog.getName());
63         type.setClassName(dialog.getClassName());
64         type.setLibraryEntry(dialog.getLibraryEntry());
65         addContent(type);
66     }
67     
68     /**
69      * Creates the tab item that contains this sub-page.
70      */

71     protected TabItem createTabItem(TabFolder folder) {
72         TabItem item = new TabItem(folder, SWT.NONE);
73         item.setText(AntPreferencesMessages.AntTypesPage_typesPageTitle);
74         item.setImage(AntObjectLabelProvider.getTypeImage());
75         item.setData(this);
76         Composite top = new Composite(folder, SWT.NONE);
77         top.setFont(folder.getFont());
78         item.setControl(createContents(top));
79         
80         connectToFolder(item, folder);
81                 
82         return item;
83     }
84     
85     /* (non-Javadoc)
86      * @see org.eclipse.ant.internal.ui.preferences.AntPage#edit(org.eclipse.jface.viewers.IStructuredSelection)
87      */

88     protected void edit(IStructuredSelection selection) {
89         Type type = (Type) selection.getFirstElement();
90         String JavaDoc title = AntPreferencesMessages.AntTypesPage_editTypeDialogTitle;
91         AddCustomDialog dialog = getCustomDialog(title, IAntUIHelpContextIds.EDIT_TYPE_DIALOG);
92         dialog.setClassName(type.getClassName());
93         dialog.setName(type.getTypeName());
94         dialog.setLibraryEntry(type.getLibraryEntry());
95         if (dialog.open() == Window.CANCEL) {
96             return;
97         }
98
99         type.setTypeName(dialog.getName());
100         type.setClassName(dialog.getClassName());
101         type.setLibraryEntry(dialog.getLibraryEntry());
102         updateContent(type);
103     }
104     
105     private AddCustomDialog getCustomDialog(String JavaDoc title, String JavaDoc helpContext) {
106         Iterator JavaDoc types= getContents(true).iterator();
107         List JavaDoc names= new ArrayList JavaDoc();
108         while (types.hasNext()) {
109             Type aTask = (Type) types.next();
110             names.add(aTask.getTypeName());
111         }
112         
113         AddCustomDialog dialog = new AddCustomDialog(getShell(), getPreferencePage().getLibraryEntries(), names, helpContext);
114         dialog.setTitle(title);
115         dialog.setAlreadyExistsErrorMsg(AntPreferencesMessages.AntTypesPage_8);
116         dialog.setNoNameErrorMsg(AntPreferencesMessages.AntTypesPage_9);
117         return dialog;
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.ant.internal.ui.preferences.AntPage#initialize()
122      */

123     protected void initialize() {
124         AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
125         setInput(prefs.getTypes());
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.ant.internal.ui.preferences.AntPage#getHelpContextId()
130      */

131     protected String JavaDoc getHelpContextId() {
132         return IAntUIHelpContextIds.ANT_TYPES_PAGE;
133     }
134 }
135
Popular Tags