package net.sourceforge.phpeclipse.preferences; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.PropertyPage; /** * * This page will be added to the project's property page dialog when the "Properties..." popup menu item is selected */ public class PHPObfuscatorPropertyPage extends PropertyPage implements IObfuscatorPreferences { private Text publishText; // private DirectoryFieldEditor dfe; private Group group; private ProjectProperties properties; private Control buildUI(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); RowLayout rowLayout = new RowLayout(); rowLayout.type = SWT.VERTICAL; rowLayout.wrap = false; composite.setLayout(rowLayout); // hasNature = new Button(composite,SWT.CHECK); // hasNature.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.hasnature")); // hasNature.addSelectionListener(new SelectionListener() // { // public void widgetDefaultSelected(SelectionEvent e) // { // group.setEnabled(hasNature.getSelection()); // } // // public void widgetSelected(SelectionEvent e) // { // group.setEnabled(hasNature.getSelection()); // } // }); group = new Group(composite, SWT.NONE); group.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.properties")); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; group.setLayout(gridLayout); Label label = new Label(group, SWT.RIGHT); label.setText(PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish")); publishText = new Text(group, SWT.LEFT); publishText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); // dfe = // new DirectoryFieldEditor( // "PHPObfuscatorPropertyPage.publish", // PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.publish"), // group); return composite; } public void readProperties() throws CoreException { publishText.setText(properties.getPublish()); // dfe.loadDefault(); // hasNature.setSelection(properties.hasNature()); // group.setEnabled(hasNature.getSelection()); group.setEnabled(true); } public void writeProperties() throws CoreException { // properties.setNature(hasNature.getSelection()); properties.setPublish(publishText.getText()); // dfe.store(); } public Control createContents(Composite parent) { Control control = buildUI(parent); try { IAdaptable adaptable = getElement(); if (adaptable instanceof IProject) { properties = new ProjectProperties((IProject) adaptable); readProperties(); } } catch (CoreException x) { ErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"), makeStatus(x)); } return control; } public boolean performOk() { try { writeProperties(); } catch (CoreException x) { ErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"), makeStatus(x)); } return super.performOk(); } public void performApply() { try { writeProperties(); } catch (CoreException x) { ErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.dialogtitle"), PHPPreferencesMessages.getString("PHPObfuscatorPropertyPage.propertyerror"), makeStatus(x)); } super.performApply(); } /** * Create an IStatus object from an exception. * @param x exception to process * @return IStatus status object for the above exception */ public static IStatus makeStatus(Exception x) { // Throwable t = popThrowables(x); // if(t instanceof CoreException) // return ((CoreException)t).getStatus(); // else return new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, x.getMessage(), x); } public void performDefaults() { // hasNature.setSelection(true); publishText.setText(DEFAULT_PUBLISH_DIR); super.performDefaults(); } }