Commiting more changes to fix RSE issues with PHP projects.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / preferences / PHPProjectPropertyPage.java
1 package net.sourceforge.phpeclipse.preferences;
2
3 import net.sourceforge.phpdt.internal.core.JavaProject;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
5
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;
21
22 public class PHPProjectPropertyPage extends PropertyPage implements
23                 IWorkbenchPropertyPage {
24         protected PHPProjectLibraryPage projectsPage;
25
26         protected JavaProject workingProject;
27
28         public PHPProjectPropertyPage() {
29         }
30
31         protected Control createContents(Composite parent) {
32                 noDefaultAndApplyButton();
33
34                 workingProject = getPHPProject();
35                 if (workingProject == null || !workingProject.getProject().isOpen())
36                         return createClosedProjectPageContents(parent);
37
38                 return createProjectPageContents(parent);
39         }
40
41         protected JavaProject getPHPProject() {
42                 IAdaptable selectedElement = getElement();
43                 if (selectedElement == null)
44                         return null;
45
46                 if (selectedElement instanceof JavaProject)
47                         return (JavaProject) selectedElement;
48
49                 if (selectedElement instanceof IProject) {
50                         IProject simpleProject = (IProject) selectedElement;
51                         try {
52                                 if (simpleProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
53                                         JavaProject phpProject = new JavaProject();
54                                         phpProject.setProject(simpleProject);
55                                         return phpProject;
56                                 }
57                         } catch (CoreException e) {
58                                 PHPeclipsePlugin.log(e);
59                         }
60                 }
61
62                 return null;
63         }
64
65         protected Control createClosedProjectPageContents(Composite parent) {
66                 Label label = new Label(parent, SWT.NONE);
67                 label.setText(PHPPreferencesMessages
68                                 .getString("PHPProjectPropertyPage.phpProjectClosed")); //$NON-NLS-1$
69
70                 return label;
71         }
72
73         protected Control createProjectPageContents(Composite parent) {
74                 TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
75                 tabFolder.setLayout(new GridLayout());
76                 tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
77                 tabFolder.addSelectionListener(new SelectionAdapter() {
78                         public void widgetSelected(SelectionEvent e) {
79                                 // tabChanged(e.item);
80                         }
81                 });
82
83                 projectsPage = new PHPProjectLibraryPage(workingProject);
84                 TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
85                 tabItem.setText(PHPPreferencesMessages
86                                 .getString("PHPProjectLibraryPage.tabName")); //$NON-NLS-1$
87                 // tabItem.setData(projectsPage);
88                 tabItem.setControl(projectsPage.getControl(tabFolder));
89
90                 return tabFolder;
91         }
92
93         public boolean performOk() {
94                 try {
95                         projectsPage.getWorkingProject().save();
96                 } catch (CoreException e) {
97                         PHPeclipsePlugin.log(e);
98                 }
99                 return super.performOk();
100         }
101
102 }