70e520049773522d5a24aa15cec2ee8a638c5e46
[phpeclipse.git] /
1 package net.sourceforge.phpeclipse.preferences;
2
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4
5 import org.eclipse.core.resources.IProject;
6 import org.eclipse.core.runtime.CoreException;
7 import org.eclipse.core.runtime.IAdaptable;
8 import org.eclipse.core.runtime.IStatus;
9 import org.eclipse.core.runtime.Status;
10 import org.eclipse.jface.dialogs.ErrorDialog;
11 import org.eclipse.jface.preference.DirectoryFieldEditor;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.layout.RowLayout;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Group;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Text;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.dialogs.PropertyPage;
23
24 /**
25  *
26  * This page will be added to the project's property page dialog when the "Properties..." popup menu item is selected
27  */
28 public class PHPObfuscatorPropertyPage extends PropertyPage implements IObfuscatorPreferences {
29   private Text publishText;
30  // private DirectoryFieldEditor dfe;
31   private Group group;
32   private ProjectProperties properties;
33
34   private Control buildUI(Composite parent) {
35     Composite composite = new Composite(parent, SWT.NULL);
36     RowLayout rowLayout = new RowLayout();
37     rowLayout.type = SWT.VERTICAL;
38     rowLayout.wrap = false;
39     composite.setLayout(rowLayout);
40     //      hasNature = new Button(composite,SWT.CHECK);
41     //      hasNature.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.hasnature"));
42     //      hasNature.addSelectionListener(new SelectionListener()
43     //      {
44     //         public void widgetDefaultSelected(SelectionEvent e)
45     //         {
46     //            group.setEnabled(hasNature.getSelection());
47     //         }
48     //         
49     //         public void widgetSelected(SelectionEvent e)
50     //         {
51     //          group.setEnabled(hasNature.getSelection());
52     //         }
53     //      });
54     group = new Group(composite, SWT.NONE);
55     group.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.properties"));
56     GridLayout gridLayout = new GridLayout();
57     gridLayout.numColumns = 2;
58     group.setLayout(gridLayout);
59
60     Label label = new Label(group, SWT.RIGHT);
61     label.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"));
62     publishText = new Text(group, SWT.LEFT);
63     publishText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
64
65 //    dfe =
66 //      new DirectoryFieldEditor(
67 //        "PHPObfuscatorPropertyPage.publish",
68 //        PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"),
69 //        group);
70
71     return composite;
72   }
73
74   public void readProperties() throws CoreException {
75     publishText.setText(properties.getPublish());
76  //   dfe.loadDefault();
77     //       hasNature.setSelection(properties.hasNature());
78     //       group.setEnabled(hasNature.getSelection());
79     group.setEnabled(true);
80   }
81
82   public void writeProperties() throws CoreException {
83     //   properties.setNature(hasNature.getSelection());
84     properties.setPublish(publishText.getText());
85   //  dfe.store();
86   }
87
88   public Control createContents(Composite parent) {
89     Control control = buildUI(parent);
90     try {
91       IAdaptable adaptable = getElement();
92       if (adaptable instanceof IProject) {
93         properties = new ProjectProperties((IProject) adaptable);
94         readProperties();
95       }
96     } catch (CoreException x) {
97       ErrorDialog.openError(
98         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
99         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
100         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
101         makeStatus(x));
102     }
103     return control;
104   }
105
106   public boolean performOk() {
107     try {
108       writeProperties();
109     } catch (CoreException x) {
110       ErrorDialog.openError(
111         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
112         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
113         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
114         makeStatus(x));
115     }
116     return super.performOk();
117   }
118
119   public void performApply() {
120     try {
121       writeProperties();
122     } catch (CoreException x) {
123       ErrorDialog.openError(
124         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
125         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
126         PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
127         makeStatus(x));
128     }
129     super.performApply();
130   }
131   /**
132    * Create an IStatus object from an exception.
133    * @param x exception to process
134    * @return IStatus status object for the above exception
135    */
136   public static IStatus makeStatus(Exception x) {
137     //     Throwable t = popThrowables(x);
138     //     if(t instanceof CoreException)
139     //        return ((CoreException)t).getStatus();
140     //     else
141     return new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, x.getMessage(), x);
142   }
143   public void performDefaults() {
144     //    hasNature.setSelection(true);
145     publishText.setText(DEFAULT_PUBLISH_DIR);
146     super.performDefaults();
147   }
148 }