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.help.WorkbenchHelp;
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;
46 private ComboDialogField fPriorityDialogField;
48 private List fExistingNames;
50 public TodoTaskInputDialog(Shell parent, TodoTask task, List existingEntries) {
53 fExistingNames= new ArrayList(existingEntries.size());
54 for (int i= 0; i < existingEntries.size(); i++) {
55 TodoTask curr= (TodoTask) existingEntries.get(i);
56 if (!curr.equals(task)) {
57 fExistingNames.add(curr.name);
62 setTitle(PreferencesMessages.getString("TodoTaskInputDialog.new.title")); //$NON-NLS-1$
64 setTitle(PreferencesMessages.getString("TodoTaskInputDialog.edit.title")); //$NON-NLS-1$
67 CompilerTodoTaskInputAdapter adapter= new CompilerTodoTaskInputAdapter();
69 fNameDialogField= new StringDialogField();
70 fNameDialogField.setLabelText(PreferencesMessages.getString("TodoTaskInputDialog.name.label")); //$NON-NLS-1$
71 fNameDialogField.setDialogFieldListener(adapter);
73 fNameDialogField.setText((task != null) ? task.name : ""); //$NON-NLS-1$
75 String[] items= new String[] {
76 PreferencesMessages.getString("TodoTaskInputDialog.priority.high"), //$NON-NLS-1$
77 PreferencesMessages.getString("TodoTaskInputDialog.priority.normal"), //$NON-NLS-1$
78 PreferencesMessages.getString("TodoTaskInputDialog.priority.low") //$NON-NLS-1$
81 fPriorityDialogField= new ComboDialogField(SWT.READ_ONLY);
82 fPriorityDialogField.setLabelText(PreferencesMessages.getString("TodoTaskInputDialog.priority.label")); //$NON-NLS-1$
83 fPriorityDialogField.setItems(items);
85 if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(task.priority)) {
86 fPriorityDialogField.selectItem(0);
87 } else if (JavaCore.COMPILER_TASK_PRIORITY_NORMAL.equals(task.priority)) {
88 fPriorityDialogField.selectItem(1);
90 fPriorityDialogField.selectItem(2);
93 fPriorityDialogField.selectItem(1);
97 public TodoTask getResult() {
98 TodoTask task= new TodoTask();
99 task.name= fNameDialogField.getText().trim();
100 switch (fPriorityDialogField.getSelectionIndex()) {
102 task.priority= JavaCore.COMPILER_TASK_PRIORITY_HIGH;
105 task.priority= JavaCore.COMPILER_TASK_PRIORITY_NORMAL;
108 task.priority= JavaCore.COMPILER_TASK_PRIORITY_LOW;
114 protected Control createDialogArea(Composite parent) {
115 Composite composite= (Composite) super.createDialogArea(parent);
117 Composite inner= new Composite(composite, SWT.NONE);
118 GridLayout layout= new GridLayout();
119 layout.marginHeight= 0;
120 layout.marginWidth= 0;
121 layout.numColumns= 2;
122 inner.setLayout(layout);
124 fNameDialogField.doFillIntoGrid(inner, 2);
125 fPriorityDialogField.doFillIntoGrid(inner, 2);
127 LayoutUtil.setHorizontalGrabbing(fNameDialogField.getTextControl(null));
128 LayoutUtil.setWidthHint(fNameDialogField.getTextControl(null), convertWidthInCharsToPixels(45));
130 fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
132 applyDialogFont(composite);
136 private void doValidation() {
137 StatusInfo status= new StatusInfo();
138 String newText= fNameDialogField.getText();
139 if (newText.length() == 0) {
140 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.enterName")); //$NON-NLS-1$
142 if (newText.indexOf(',') != -1) {
143 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.comma")); //$NON-NLS-1$
144 } else if (fExistingNames.contains(newText)) {
145 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.entryExists")); //$NON-NLS-1$
146 } else if (Character.isWhitespace(newText.charAt(0)) || Character.isWhitespace(newText.charAt(newText.length() - 1))) {
147 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.noSpace")); //$NON-NLS-1$
150 updateStatus(status);
154 * @see org.eclipse.jface.window.Window#configureShell(Shell)
156 protected void configureShell(Shell newShell) {
157 super.configureShell(newShell);
158 WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.TODO_TASK_INPUT_DIALOG);