*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / preferences / PHPObfuscatorPropertyPage.java
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 
28    extends PropertyPage
29    implements IObfuscatorPreferences
30 {
31    private Text publishText;
32 //   private Button hasNature,
33 //                   isBuild;
34    private Group group;
35    private ProjectProperties properties;
36         
37    private Control buildUI(Composite parent)
38    {
39       Composite composite = new Composite(parent,SWT.NULL);
40       RowLayout rowLayout = new RowLayout();
41       rowLayout.type = SWT.VERTICAL;
42       rowLayout.wrap = false;
43       composite.setLayout(rowLayout);
44 //      hasNature = new Button(composite,SWT.CHECK);
45 //      hasNature.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.hasnature"));
46 //      hasNature.addSelectionListener(new SelectionListener()
47 //      {
48 //         public void widgetDefaultSelected(SelectionEvent e)
49 //         {
50 //            group.setEnabled(hasNature.getSelection());
51 //         }
52 //         
53 //         public void widgetSelected(SelectionEvent e)
54 //         {
55 //          group.setEnabled(hasNature.getSelection());
56 //         }
57 //      });
58       group = new Group(composite,SWT.NONE);
59       group.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.properties"));
60       GridLayout gridLayout = new GridLayout();
61       gridLayout.numColumns = 2;
62       group.setLayout(gridLayout);
63       
64       Label label = new Label(group,SWT.RIGHT);
65       label.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"));
66       publishText = new Text(group,SWT.LEFT);
67       publishText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
68       return composite;
69    }
70
71    public void readProperties()
72       throws CoreException
73    {
74        publishText.setText(properties.getPublish());
75 //       hasNature.setSelection(properties.hasNature());
76 //       group.setEnabled(hasNature.getSelection());
77      group.setEnabled(true);
78    }
79
80    public void writeProperties()
81       throws CoreException
82    {
83    //   properties.setNature(hasNature.getSelection());
84       properties.setPublish(publishText.getText());
85    }
86
87    public Control createContents(Composite parent)
88    {
89       Control control = buildUI(parent);
90       try
91       {
92          IAdaptable adaptable = getElement();
93          if(adaptable instanceof IProject)
94          {
95           properties = new ProjectProperties((IProject)adaptable);
96             readProperties();
97          }
98       }
99       catch(CoreException x)
100       {
101          ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
102                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
103                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
104                                makeStatus(x));
105       }
106       return control;
107    }
108    
109    public boolean performOk()
110    {
111       try
112       {
113          writeProperties();
114       }
115       catch(CoreException x)
116       {
117          ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
118                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
119                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
120                                makeStatus(x));
121       }
122       return super.performOk();
123    }
124
125    public void performApply()
126    {
127       try
128       {
129          writeProperties();
130       }
131       catch(CoreException x)
132       {
133          ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
134                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"),
135                                PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"),
136                                makeStatus(x));
137       }
138       super.performApply();
139    }
140   /**
141    * Create an IStatus object from an exception.
142    * @param x exception to process
143    * @return IStatus status object for the above exception
144    */
145   public static IStatus makeStatus(Exception x)
146   {
147 //     Throwable t = popThrowables(x);
148 //     if(t instanceof CoreException)
149 //        return ((CoreException)t).getStatus();
150 //     else
151         return new Status(IStatus.ERROR,
152                            PHPeclipsePlugin.PLUGIN_ID,
153                            IStatus.ERROR,
154                            x.getMessage(),
155                            x);
156   }
157    public void performDefaults()
158    {
159   //    hasNature.setSelection(true);
160       publishText.setText(DEFAULT_PUBLISH_DIR);
161       super.performDefaults();
162    }
163 }