1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 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 33 public class AntTasksPage extends AntPage { 34 35 38 public AntTasksPage(AntRuntimePreferencePage preferencePage) { 39 super(preferencePage); 40 } 41 42 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 54 protected void add() { 55 String 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 title, String helpContext) { 69 Iterator tasks= getContents(true).iterator(); 70 List names= new ArrayList (); 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 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 102 protected void edit(IStructuredSelection selection) { 103 Task task= (Task)selection.getFirstElement(); 104 String 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 122 protected void initialize() { 123 AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences(); 124 setInput(prefs.getTasks()); 125 } 126 127 130 protected String getHelpContextId() { 131 return IAntUIHelpContextIds.ANT_TASKS_PAGE; 132 } 133 } 134 | Popular Tags |