1 package net.sourceforge.phpeclipse.preferences;
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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;
26 * This page will be added to the project's property page dialog when the "Properties..." popup menu item is selected
28 public class PHPObfuscatorPropertyPage extends PropertyPage implements IObfuscatorPreferences {
29 private Text publishText;
30 // private DirectoryFieldEditor dfe;
32 private ProjectProperties properties;
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()
44 // public void widgetDefaultSelected(SelectionEvent e)
46 // group.setEnabled(hasNature.getSelection());
49 // public void widgetSelected(SelectionEvent e)
51 // group.setEnabled(hasNature.getSelection());
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);
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));
66 // new DirectoryFieldEditor(
67 // "PHPObfuscatorPropertyPage.publish",
68 // PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"),
74 public void readProperties() throws CoreException {
75 publishText.setText(properties.getPublish());
77 // hasNature.setSelection(properties.hasNature());
78 // group.setEnabled(hasNature.getSelection());
79 group.setEnabled(true);
82 public void writeProperties() throws CoreException {
83 // properties.setNature(hasNature.getSelection());
84 properties.setPublish(publishText.getText());
88 public Control createContents(Composite parent) {
89 Control control = buildUI(parent);
91 IAdaptable adaptable = getElement();
92 if (adaptable instanceof IProject) {
93 properties = new ProjectProperties((IProject) adaptable);
96 } catch (CoreException x) {
97 ErrorDialog.openError(
98 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
99 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
100 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
106 public boolean performOk() {
109 } catch (CoreException x) {
110 ErrorDialog.openError(
111 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
112 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
113 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
116 return super.performOk();
119 public void performApply() {
122 } catch (CoreException x) {
123 ErrorDialog.openError(
124 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
125 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
126 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
129 super.performApply();
132 * Create an IStatus object from an exception.
133 * @param x exception to process
134 * @return IStatus status object for the above exception
136 public static IStatus makeStatus(Exception x) {
137 // Throwable t = popThrowables(x);
138 // if(t instanceof CoreException)
139 // return ((CoreException)t).getStatus();
141 return new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, x.getMessage(), x);
143 public void performDefaults() {
144 // hasNature.setSelection(true);
145 publishText.setText(DEFAULT_PUBLISH_DIR);
146 super.performDefaults();