KickJava   Java API By Example, From Geeks To Geeks.

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


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.Task;
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 tasks
31  * to be used when running Ant build files.
32  */

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

38     public AntTasksPage(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.AntTasksPage_1, ADD_BUTTON);
47         editButton = createPushButton(parent, AntPreferencesMessages.AntTasksPage_2, EDIT_BUTTON);
48         removeButton = createPushButton(parent, AntPreferencesMessages.AntTasksPage_3, REMOVE_BUTTON);
49     }
50     
51     /**
52      * Allows the user to enter a custom task.
53      */

54     protected void add() {
55         String JavaDoc title = AntPreferencesMessages.AntTasksPage_addTaskDialogTitle;
56         AddCustomDialog dialog = getCustomDialog(title, IAntUIHelpContextIds.ADD_TASK_DIALOG);
57         if (dialog.open() == Window.CANCEL) {
58             return;
59         }
60
61         Task task = new Task();
62         task.setTaskName(dialog.getName());
63         task.setClassName(dialog.getClassName());
64         task.setLibraryEntry(dialog.getLibraryEntry());
65         addContent(task);
66     }
67     
68     private AddCustomDialog getCustomDialog(String JavaDoc title, String JavaDoc helpContext) {
69         Iterator JavaDoc tasks= getContents(true).iterator();
70         List JavaDoc names= new ArrayList JavaDoc();
71         while (tasks.hasNext()) {
72             Task task = (Task) tasks.next();
73             names.add(task.getTaskName());
74         }
75         AddCustomDialog dialog = new AddCustomDialog(getShell(), getPreferencePage().getLibraryEntries(), names, helpContext);
76         dialog.setTitle(title);
77         dialog.setAlreadyExistsErrorMsg(AntPreferencesMessages.AntTasksPage_8);
78         dialog.setNoNameErrorMsg(AntPreferencesMessages.AntTasksPage_9);
79         return dialog;
80     }
81     
82     /**
83      * Creates the tab item that contains this sub-page.
84      */

85     protected TabItem createTabItem(TabFolder folder) {
86         TabItem item = new TabItem(folder, SWT.NONE);
87         item.setText(AntPreferencesMessages.AntTasksPage_title);
88         item.setImage(AntObjectLabelProvider.getTaskImage());
89         item.setData(this);
90         Composite top = new Composite(folder, SWT.NONE);
91         top.setFont(folder.getFont());
92         item.setControl(createContents(top));
93         
94         connectToFolder(item, folder);
95         
96         return item;
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.ant.internal.ui.preferences.AntPage#edit(org.eclipse.jface.viewers.IStructuredSelection)
101      */

102     protected void edit(IStructuredSelection selection) {
103         Task task= (Task)selection.getFirstElement();
104         String JavaDoc title = AntPreferencesMessages.AntTasksPage_editTaskDialogTitle;
105         AddCustomDialog dialog = getCustomDialog(title, IAntUIHelpContextIds.EDIT_TASK_DIALOG);
106         dialog.setClassName(task.getClassName());
107         dialog.setName(task.getTaskName());
108         dialog.setLibraryEntry(task.getLibraryEntry());
109         if (dialog.open() == Window.CANCEL) {
110             return;
111         }
112
113         task.setTaskName(dialog.getName());
114         task.setClassName(dialog.getClassName());
115         task.setLibraryEntry(dialog.getLibraryEntry());
116         updateContent(task);
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.ant.internal.ui.preferences.AntPage#initialize()
121      */

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

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