Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/eclipse/jdt/annotation/PromptForFolderDialog.java


1   package com.port80.eclipse.jdt.annotation;
2   
3   import java.util.HashSet;
4   import java.util.List;
5   import java.util.Set;
6   
7   import org.eclipse.jface.dialogs.Dialog;
8   import org.eclipse.jface.dialogs.IDialogConstants;
9   import org.eclipse.swt.SWT;
10  import org.eclipse.swt.events.ModifyEvent;
11  import org.eclipse.swt.events.ModifyListener;
12  import org.eclipse.swt.graphics.Color;
13  import org.eclipse.swt.layout.GridData;
14  import org.eclipse.swt.layout.GridLayout;
15  import org.eclipse.swt.widgets.Button;
16  import org.eclipse.swt.widgets.Combo;
17  import org.eclipse.swt.widgets.Composite;
18  import org.eclipse.swt.widgets.Control;
19  import org.eclipse.swt.widgets.Label;
20  import org.eclipse.swt.widgets.Shell;
21  
22  import com.port80.eclipse.jdt.JdtPlugin;
23  
24  /**
25   * Prompts the user a folder.
26   * 
27   * @see org.eclipse.team.internal.ccvs.ui.ReleaseCommentDialog
28   * @author chrisl
29   */
30  public class PromptForFolderDialog extends Dialog {
31  
32    private static final String NAME = "PromptForFolderDialog";
33    private static final int WIDTH_HINT = 320;
34    private static final int HEIGHT_HINT = 64;
35  
36    private String fLabel = "";
37    private String fFolder = "";
38    private List fFolders;
39    private boolean fValid;
40    private Set fFolderSet;
41    private Color fColorBlack;
42    private Color fColorBlue;
43  
44    private Combo fFolderCombo;
45    private Label fFolderLabel;
46  
47    ////////////////////////////////////////////////////////////////////////
48  
49    /**
50     * TextEdit constructor.
51     * 
52     * @param parentShell  the parent of this dialog
53     */
54    public PromptForFolderDialog(Shell parentShell, String label, String folder, List folders) {
55      super(parentShell);
56      if (label != null)
57        fLabel = label;
58      if (folder != null)
59        fFolder = folder;
60      fFolders = folders;
61      fFolderSet = new HashSet();
62    }
63  
64    /**
65     * @return A selected existing folder name or a new valid folder name.
66     * A valid folder name is not null or "".
67     */
68    public String getFolder() {
69      return fFolder;
70    }
71  
72    ////////////////////////////////////////////////////////////////////////
73  
74    /*
75     * @see Dialog#createDialogArea(Composite)
76     */
77    protected Control createDialogArea(Composite parent) {
78  
79      fColorBlack = JdtPlugin.getColor("0x000000");
80      fColorBlue = JdtPlugin.getColor("0x2020ff");
81  
82      getShell().setText(fLabel);
83      GridData data;
84      Composite composite = new Composite(parent, SWT.NULL);
85      composite.setLayout(new GridLayout(2, false));
86      data = new GridData(GridData.FILL_BOTH);
87      composite.setLayoutData(data);
88  
89      Label label = new Label(composite, SWT.NULL);
90      data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
91      label.setLayoutData(data);
92      label.setText(fLabel);
93  
94      fFolderCombo = new Combo(composite, SWT.NONE);
95      int width = 32;
96      if (fFolders != null) {
97        for (int i = 0; i < fFolders.size(); ++i) {
98          String s = (String) fFolders.get(i);
99          fFolderCombo.add(s);
100         fFolderSet.add(s);
101         if (s.length() * 2 > width)
102           width = s.length() * 2;
103       }
104     }
105     fFolderCombo.setText(fFolder);
106     data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.GRAB_HORIZONTAL);
107     data.widthHint = convertWidthInCharsToPixels(width);
108     fFolderCombo.setLayoutData(data);
109     fFolderCombo.addModifyListener(new ModifyListener() {
110       public void modifyText(ModifyEvent e) {
111         validCheck();
112       }
113     });
114     fFolderCombo.setEnabled(true);
115     fValid = true;
116     return composite;
117   }
118 
119   /*
120    * @see Dialog#okPressed
121    */
122   protected void okPressed() {
123     fFolder = fFolderCombo.getText();
124     // Clean up the folder name.
125     StringBuffer buf = new StringBuffer();
126     char c;
127     for (int i = 0; i < fFolder.length(); ++i) {
128       c = fFolder.charAt(i);
129       if (c >= ' ' && c < 0x80)
130         buf.append(c);
131     }
132     fFolder = buf.toString();
133     super.okPressed();
134   }
135 
136   ////////////////////////////////////////////////////////////////////////
137 
138   void validCheck() {
139     String folder = fFolderCombo.getText();
140     boolean valid = (folder.length() > 0);
141     if (valid != fValid) {
142       fValid = valid;
143       Button ok = getButton(IDialogConstants.OK_ID);
144       if (ok != null)
145         ok.setEnabled(fValid);
146       if (fFolderSet.contains(folder)) {
147         fFolderCombo.setForeground(fColorBlack);
148       } else {
149         fFolderCombo.setForeground(fColorBlue);
150       }
151     }
152   }
153 
154   ////////////////////////////////////////////////////////////////////////
155 }