1 package net.sourceforge.phpeclipse.preferences;
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
6 import org.eclipse.core.resources.IProject;
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.core.runtime.IAdaptable;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.SelectionAdapter;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.TabFolder;
18 import org.eclipse.swt.widgets.TabItem;
19 import org.eclipse.ui.IWorkbenchPropertyPage;
20 import org.eclipse.ui.dialogs.PropertyPage;
22 public class PHPProjectPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
23 protected PHPProjectLibraryPage projectsPage;
24 protected PHPProject workingProject;
26 public PHPProjectPropertyPage() {
29 protected Control createContents(Composite parent) {
30 noDefaultAndApplyButton();
32 workingProject = getPHPProject();
33 if (workingProject == null || !workingProject.getProject().isOpen())
34 return createClosedProjectPageContents(parent);
36 return createProjectPageContents(parent);
39 protected PHPProject getPHPProject() {
40 IAdaptable selectedElement = getElement();
41 if (selectedElement == null)
44 if (selectedElement instanceof PHPProject)
45 return (PHPProject) selectedElement;
47 if (selectedElement instanceof IProject) {
48 IProject simpleProject = (IProject) selectedElement;
50 if (simpleProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
51 PHPProject phpProject = new PHPProject();
52 phpProject.setProject(simpleProject);
55 } catch (CoreException e) {
56 PHPeclipsePlugin.log(e);
63 protected Control createClosedProjectPageContents(Composite parent) {
64 Label label = new Label(parent, SWT.NONE);
65 label.setText(PHPPreferencesMessages.getString("PHPProjectPropertyPage.phpProjectClosed")); //$NON-NLS-1$
70 protected Control createProjectPageContents(Composite parent) {
71 TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
72 tabFolder.setLayout(new GridLayout());
73 tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
74 tabFolder.addSelectionListener(new SelectionAdapter() {
75 public void widgetSelected(SelectionEvent e) {
80 projectsPage = new PHPProjectLibraryPage(workingProject);
81 TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
82 tabItem.setText(PHPPreferencesMessages.getString("PHPProjectLibraryPage.tabName")); //$NON-NLS-1$
83 // tabItem.setData(projectsPage);
84 tabItem.setControl(projectsPage.getControl(tabFolder));
88 public boolean performOk() {
90 projectsPage.getWorkingProject().save();
91 } catch (CoreException e) {
92 PHPeclipsePlugin.log(e);
94 return super.performOk();