1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
13 import java.util.ArrayList;
14 import java.util.List;
16 import net.sourceforge.phpdt.core.JavaCore;
17 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
18 import net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog;
19 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
20 import net.sourceforge.phpdt.internal.ui.preferences.TodoTaskConfigurationBlock.TodoTask;
21 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.ComboDialogField;
22 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField;
23 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
24 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.LayoutUtil;
25 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.StringDialogField;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.ui.PlatformUI;
35 * Dialog to enter a na new task tag
37 public class TodoTaskInputDialog extends StatusDialog {
39 private class CompilerTodoTaskInputAdapter implements IDialogFieldListener {
40 public void dialogFieldChanged(DialogField field) {
45 private StringDialogField fNameDialogField;
47 private ComboDialogField fPriorityDialogField;
49 private List fExistingNames;
51 public TodoTaskInputDialog(Shell parent, TodoTask task, List existingEntries) {
54 fExistingNames = new ArrayList(existingEntries.size());
55 for (int i = 0; i < existingEntries.size(); i++) {
56 TodoTask curr = (TodoTask) existingEntries.get(i);
57 if (!curr.equals(task)) {
58 fExistingNames.add(curr.name);
63 setTitle(PreferencesMessages
64 .getString("TodoTaskInputDialog.new.title")); //$NON-NLS-1$
66 setTitle(PreferencesMessages
67 .getString("TodoTaskInputDialog.edit.title")); //$NON-NLS-1$
70 CompilerTodoTaskInputAdapter adapter = new CompilerTodoTaskInputAdapter();
72 fNameDialogField = new StringDialogField();
73 fNameDialogField.setLabelText(PreferencesMessages
74 .getString("TodoTaskInputDialog.name.label")); //$NON-NLS-1$
75 fNameDialogField.setDialogFieldListener(adapter);
77 fNameDialogField.setText((task != null) ? task.name : ""); //$NON-NLS-1$
79 String[] items = new String[] {
81 .getString("TodoTaskInputDialog.priority.high"), //$NON-NLS-1$
83 .getString("TodoTaskInputDialog.priority.normal"), //$NON-NLS-1$
85 .getString("TodoTaskInputDialog.priority.low") //$NON-NLS-1$
88 fPriorityDialogField = new ComboDialogField(SWT.READ_ONLY);
89 fPriorityDialogField.setLabelText(PreferencesMessages
90 .getString("TodoTaskInputDialog.priority.label")); //$NON-NLS-1$
91 fPriorityDialogField.setItems(items);
93 if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(task.priority)) {
94 fPriorityDialogField.selectItem(0);
95 } else if (JavaCore.COMPILER_TASK_PRIORITY_NORMAL
96 .equals(task.priority)) {
97 fPriorityDialogField.selectItem(1);
99 fPriorityDialogField.selectItem(2);
102 fPriorityDialogField.selectItem(1);
106 public TodoTask getResult() {
107 TodoTask task = new TodoTask();
108 task.name = fNameDialogField.getText().trim();
109 switch (fPriorityDialogField.getSelectionIndex()) {
111 task.priority = JavaCore.COMPILER_TASK_PRIORITY_HIGH;
114 task.priority = JavaCore.COMPILER_TASK_PRIORITY_NORMAL;
117 task.priority = JavaCore.COMPILER_TASK_PRIORITY_LOW;
123 protected Control createDialogArea(Composite parent) {
124 Composite composite = (Composite) super.createDialogArea(parent);
126 Composite inner = new Composite(composite, SWT.NONE);
127 GridLayout layout = new GridLayout();
128 layout.marginHeight = 0;
129 layout.marginWidth = 0;
130 layout.numColumns = 2;
131 inner.setLayout(layout);
133 fNameDialogField.doFillIntoGrid(inner, 2);
134 fPriorityDialogField.doFillIntoGrid(inner, 2);
136 LayoutUtil.setHorizontalGrabbing(fNameDialogField.getTextControl(null));
137 LayoutUtil.setWidthHint(fNameDialogField.getTextControl(null),
138 convertWidthInCharsToPixels(45));
140 fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
142 applyDialogFont(composite);
146 private void doValidation() {
147 StatusInfo status = new StatusInfo();
148 String newText = fNameDialogField.getText();
149 if (newText.length() == 0) {
150 status.setError(PreferencesMessages
151 .getString("TodoTaskInputDialog.error.enterName")); //$NON-NLS-1$
153 if (newText.indexOf(',') != -1) {
154 status.setError(PreferencesMessages
155 .getString("TodoTaskInputDialog.error.comma")); //$NON-NLS-1$
156 } else if (fExistingNames.contains(newText)) {
157 status.setError(PreferencesMessages
158 .getString("TodoTaskInputDialog.error.entryExists")); //$NON-NLS-1$
159 } else if (Character.isWhitespace(newText.charAt(0))
160 || Character.isWhitespace(newText
161 .charAt(newText.length() - 1))) {
162 status.setError(PreferencesMessages
163 .getString("TodoTaskInputDialog.error.noSpace")); //$NON-NLS-1$
166 updateStatus(status);
170 * @see org.eclipse.jface.window.Window#configureShell(Shell)
172 protected void configureShell(Shell newShell) {
173 super.configureShell(newShell);
174 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
175 IJavaHelpContextIds.TODO_TASK_INPUT_DIALOG);