1 package net.sourceforge.phpeclipse.preferences;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Iterator;
8 import net.sourceforge.phpdt.internal.core.JavaProject;
9 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
11 import org.eclipse.core.resources.IProject;
12 import org.eclipse.core.resources.IWorkspaceRoot;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jface.viewers.CheckStateChangedEvent;
15 import org.eclipse.jface.viewers.CheckboxTableViewer;
16 import org.eclipse.jface.viewers.ICheckStateListener;
17 import org.eclipse.jface.viewers.IContentProvider;
18 import org.eclipse.jface.viewers.ILabelProviderListener;
19 import org.eclipse.jface.viewers.IStructuredContentProvider;
20 import org.eclipse.jface.viewers.ITableLabelProvider;
21 import org.eclipse.jface.viewers.Viewer;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.layout.FillLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Table;
28 import org.eclipse.swt.widgets.TableColumn;
29 import org.eclipse.ui.IWorkbench;
30 import org.eclipse.ui.ide.IDE.SharedImages;
32 public class PHPProjectLibraryPage {
33 protected JavaProject workingProject;
35 protected PHPProjectLibraryPage(JavaProject theWorkingProject) {
37 workingProject = theWorkingProject;
40 protected Control getControl(Composite parent) {
41 Composite composite = new Composite(parent, SWT.NONE);
42 composite.setLayout(new FillLayout());
44 Table projectsTable = new Table(composite, SWT.CHECK | SWT.BORDER
45 | SWT.MULTI | SWT.FULL_SELECTION);
46 projectsTable.setHeaderVisible(false);
47 projectsTable.setLinesVisible(false);
48 projectsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
50 TableColumn tableColumn = new TableColumn(projectsTable, SWT.NONE);
51 tableColumn.setWidth(200);
52 tableColumn.setText(PHPPreferencesMessages
53 .getString("PHPEditorPreferencePageLibraryPage.project")); //$NON-NLS-1$
55 CheckboxTableViewer projectsTableViewer = new CheckboxTableViewer(
57 projectsTableViewer.addCheckStateListener(new ICheckStateListener() {
58 public void checkStateChanged(CheckStateChangedEvent event) {
59 projectCheckedUnchecked(event);
63 projectsTableViewer.setContentProvider(getContentProvider());
64 projectsTableViewer.setLabelProvider(getLabelProvider());
66 projectsTableViewer.setInput(getWorkspaceProjects());
67 projectsTableViewer.setCheckedElements(workingProject
68 .getReferencedProjects().toArray());
73 protected void projectCheckedUnchecked(CheckStateChangedEvent event) {
74 IProject checkEventProject = (IProject) event.getElement();
75 if (event.getChecked())
76 getWorkingProject().addLoadPathEntry(checkEventProject);
78 getWorkingProject().removeLoadPathEntry(checkEventProject);
81 protected JavaProject getWorkingProject() {
82 return workingProject;
85 protected List getWorkspaceProjects() {
86 IWorkspaceRoot root = PHPeclipsePlugin.getWorkspace().getRoot();
87 return Arrays.asList(root.getProjects());
90 protected ITableLabelProvider getLabelProvider() {
91 ITableLabelProvider labelProvider = new ITableLabelProvider() {
92 public Image getColumnImage(Object element, int columnIndex) {
93 IWorkbench workbench = PHPeclipsePlugin.getDefault()
95 return workbench.getSharedImages().getImage(
96 SharedImages.IMG_OBJ_PROJECT);
99 public String getColumnText(Object element, int columnIndex) {
100 if (element instanceof IProject)
101 return ((IProject) element).getName();
103 return PHPPreferencesMessages
104 .getString("PHPEditorPreferencePageLibraryPage.elementNotIProject"); //$NON-NLS-1$
107 public void addListener(ILabelProviderListener listener) {
110 public void dispose() {
113 public boolean isLabelProperty(Object element, String property) {
117 public void removeListener(ILabelProviderListener listener) {
121 return labelProvider;
124 protected IContentProvider getContentProvider() {
125 IStructuredContentProvider contentProvider = new IStructuredContentProvider() {
126 protected List PHPEditorPreferencePages;
128 public Object[] getElements(Object inputElement) {
129 return PHPEditorPreferencePages.toArray();
132 public void dispose() {
135 public void inputChanged(Viewer viewer, Object oldInput,
137 PHPEditorPreferencePages = new ArrayList();
139 if (!(newInput instanceof List))
142 Iterator workspaceProjectsIterator = ((List) newInput)
144 while (workspaceProjectsIterator.hasNext()) {
145 Object anObject = workspaceProjectsIterator.next();
146 if (anObject instanceof IProject) {
147 IProject project = (IProject) anObject;
148 if (project.getName() != workingProject.getProject()
152 .hasNature(PHPeclipsePlugin.PHP_NATURE_ID))
153 PHPEditorPreferencePages.add(project);
154 } catch (CoreException e) {
162 return contentProvider;