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