Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
[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 IWorkbenchPropertyPage {
23   protected PHPProjectLibraryPage projectsPage;
24   protected JavaProject workingProject;
25
26   public PHPProjectPropertyPage() {
27   }
28
29   protected Control createContents(Composite parent) {
30     noDefaultAndApplyButton();
31
32     workingProject = getPHPProject();
33     if (workingProject == null || !workingProject.getProject().isOpen())
34       return createClosedProjectPageContents(parent);
35
36     return createProjectPageContents(parent);
37   }
38
39   protected JavaProject getPHPProject() {
40     IAdaptable selectedElement = getElement();
41     if (selectedElement == null)
42       return null;
43
44     if (selectedElement instanceof JavaProject)
45       return (JavaProject) selectedElement;
46
47     if (selectedElement instanceof IProject) {
48       IProject simpleProject = (IProject) selectedElement;
49       try {
50         if (simpleProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
51           JavaProject phpProject = new JavaProject();
52           phpProject.setProject(simpleProject);
53           return phpProject;
54         }
55       } catch (CoreException e) {
56         PHPeclipsePlugin.log(e);
57       }
58     }
59
60     return null;
61   }
62
63   protected Control createClosedProjectPageContents(Composite parent) {
64     Label label = new Label(parent, SWT.NONE);
65     label.setText(PHPPreferencesMessages.getString("PHPProjectPropertyPage.phpProjectClosed")); //$NON-NLS-1$
66
67     return label;
68   }
69
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) {
76         //tabChanged(e.item);
77       }
78     });
79
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));
85
86     return tabFolder;
87   }
88   public boolean performOk() {
89     try {
90       projectsPage.getWorkingProject().save();
91     } catch (CoreException e) {
92       PHPeclipsePlugin.log(e);
93     }
94     return super.performOk();
95   }
96
97 }