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 org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.help.WorkbenchHelp;
24 import net.sourceforge.phpdt.core.JavaCore;
26 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
27 import net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog;
28 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
29 import net.sourceforge.phpdt.internal.ui.preferences.TodoTaskConfigurationBlock.TodoTask;
30 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.ComboDialogField;
31 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField;
32 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
33 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.LayoutUtil;
34 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.StringDialogField;
37 * Dialog to enter a na new task tag
39 public class TodoTaskInputDialog extends StatusDialog {
41 private class CompilerTodoTaskInputAdapter implements IDialogFieldListener {
42 public void dialogFieldChanged(DialogField field) {
47 private StringDialogField fNameDialogField;
48 private ComboDialogField fPriorityDialogField;
50 private List fExistingNames;
52 public TodoTaskInputDialog(Shell parent, TodoTask task, List existingEntries) {
55 fExistingNames= new ArrayList(existingEntries.size());
56 for (int i= 0; i < existingEntries.size(); i++) {
57 TodoTask curr= (TodoTask) existingEntries.get(i);
58 if (!curr.equals(task)) {
59 fExistingNames.add(curr.name);
64 setTitle(PreferencesMessages.getString("TodoTaskInputDialog.new.title")); //$NON-NLS-1$
66 setTitle(PreferencesMessages.getString("TodoTaskInputDialog.edit.title")); //$NON-NLS-1$
69 CompilerTodoTaskInputAdapter adapter= new CompilerTodoTaskInputAdapter();
71 fNameDialogField= new StringDialogField();
72 fNameDialogField.setLabelText(PreferencesMessages.getString("TodoTaskInputDialog.name.label")); //$NON-NLS-1$
73 fNameDialogField.setDialogFieldListener(adapter);
75 fNameDialogField.setText((task != null) ? task.name : ""); //$NON-NLS-1$
77 String[] items= new String[] {
78 PreferencesMessages.getString("TodoTaskInputDialog.priority.high"), //$NON-NLS-1$
79 PreferencesMessages.getString("TodoTaskInputDialog.priority.normal"), //$NON-NLS-1$
80 PreferencesMessages.getString("TodoTaskInputDialog.priority.low") //$NON-NLS-1$
83 fPriorityDialogField= new ComboDialogField(SWT.READ_ONLY);
84 fPriorityDialogField.setLabelText(PreferencesMessages.getString("TodoTaskInputDialog.priority.label")); //$NON-NLS-1$
85 fPriorityDialogField.setItems(items);
87 if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(task.priority)) {
88 fPriorityDialogField.selectItem(0);
89 } else if (JavaCore.COMPILER_TASK_PRIORITY_NORMAL.equals(task.priority)) {
90 fPriorityDialogField.selectItem(1);
92 fPriorityDialogField.selectItem(2);
95 fPriorityDialogField.selectItem(1);
99 public TodoTask getResult() {
100 TodoTask task= new TodoTask();
101 task.name= fNameDialogField.getText().trim();
102 switch (fPriorityDialogField.getSelectionIndex()) {
104 task.priority= JavaCore.COMPILER_TASK_PRIORITY_HIGH;
107 task.priority= JavaCore.COMPILER_TASK_PRIORITY_NORMAL;
110 task.priority= JavaCore.COMPILER_TASK_PRIORITY_LOW;
116 protected Control createDialogArea(Composite parent) {
117 Composite composite= (Composite) super.createDialogArea(parent);
119 Composite inner= new Composite(composite, SWT.NONE);
120 GridLayout layout= new GridLayout();
121 layout.marginHeight= 0;
122 layout.marginWidth= 0;
123 layout.numColumns= 2;
124 inner.setLayout(layout);
126 fNameDialogField.doFillIntoGrid(inner, 2);
127 fPriorityDialogField.doFillIntoGrid(inner, 2);
129 LayoutUtil.setHorizontalGrabbing(fNameDialogField.getTextControl(null));
130 LayoutUtil.setWidthHint(fNameDialogField.getTextControl(null), convertWidthInCharsToPixels(45));
132 fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
134 applyDialogFont(composite);
138 private void doValidation() {
139 StatusInfo status= new StatusInfo();
140 String newText= fNameDialogField.getText();
141 if (newText.length() == 0) {
142 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.enterName")); //$NON-NLS-1$
144 if (newText.indexOf(',') != -1) {
145 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.comma")); //$NON-NLS-1$
146 } else if (fExistingNames.contains(newText)) {
147 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.entryExists")); //$NON-NLS-1$
148 } else if (Character.isWhitespace(newText.charAt(0)) || Character.isWhitespace(newText.charAt(newText.length() - 1))) {
149 status.setError(PreferencesMessages.getString("TodoTaskInputDialog.error.noSpace")); //$NON-NLS-1$
152 updateStatus(status);
156 * @see org.eclipse.jface.window.Window#configureShell(Shell)
158 protected void configureShell(Shell newShell) {
159 super.configureShell(newShell);
160 WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.TODO_TASK_INPUT_DIALOG);