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.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;
25 * This page will be added to the project's property page dialog when the "Properties..." popup menu item is selected
27 public class PHPObfuscatorPropertyPage extends PropertyPage implements IObfuscatorPreferences {
28 private Text publishText;
29 // private DirectoryFieldEditor dfe;
31 private ProjectProperties properties;
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()
43 // public void widgetDefaultSelected(SelectionEvent e)
45 // group.setEnabled(hasNature.getSelection());
48 // public void widgetSelected(SelectionEvent e)
50 // group.setEnabled(hasNature.getSelection());
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);
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));
65 // new DirectoryFieldEditor(
66 // "PHPObfuscatorPropertyPage.publish",
67 // PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"),
73 public void readProperties() throws CoreException {
74 publishText.setText(properties.getPublish());
76 // hasNature.setSelection(properties.hasNature());
77 // group.setEnabled(hasNature.getSelection());
78 group.setEnabled(true);
81 public void writeProperties() throws CoreException {
82 // properties.setNature(hasNature.getSelection());
83 properties.setPublish(publishText.getText());
87 public Control createContents(Composite parent) {
88 Control control = buildUI(parent);
90 IAdaptable adaptable = getElement();
91 if (adaptable instanceof IProject) {
92 properties = new ProjectProperties((IProject) adaptable);
95 } catch (CoreException x) {
96 ErrorDialog.openError(
97 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
98 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
99 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
105 public boolean performOk() {
108 } catch (CoreException x) {
109 ErrorDialog.openError(
110 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
111 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
112 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
115 return super.performOk();
118 public void performApply() {
121 } catch (CoreException x) {
122 ErrorDialog.openError(
123 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
124 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
125 PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
128 super.performApply();
131 * Create an IStatus object from an exception.
132 * @param x exception to process
133 * @return IStatus status object for the above exception
135 public static IStatus makeStatus(Exception x) {
136 // Throwable t = popThrowables(x);
137 // if(t instanceof CoreException)
138 // return ((CoreException)t).getStatus();
140 return new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, x.getMessage(), x);
142 public void performDefaults() {
143 // hasNature.setSelection(true);
144 publishText.setText(DEFAULT_PUBLISH_DIR);
145 super.performDefaults();