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;
10 import net.sourceforge.phpeclipse.ui.WebUI;
12 import org.eclipse.core.resources.IProject;
13 import org.eclipse.core.resources.IWorkspaceRoot;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jface.viewers.CheckStateChangedEvent;
16 import org.eclipse.jface.viewers.CheckboxTableViewer;
17 import org.eclipse.jface.viewers.ICheckStateListener;
18 import org.eclipse.jface.viewers.IContentProvider;
19 import org.eclipse.jface.viewers.ILabelProviderListener;
20 import org.eclipse.jface.viewers.IStructuredContentProvider;
21 import org.eclipse.jface.viewers.ITableLabelProvider;
22 import org.eclipse.jface.viewers.Viewer;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.layout.FillLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Table;
29 import org.eclipse.swt.widgets.TableColumn;
30 import org.eclipse.ui.IWorkbench;
31 import org.eclipse.ui.ide.IDE.SharedImages;
33 public class PHPProjectLibraryPage {
34 protected JavaProject workingProject;
36 protected PHPProjectLibraryPage(JavaProject theWorkingProject) {
38 workingProject = theWorkingProject;
41 protected Control getControl(Composite parent) {
42 Composite composite = new Composite(parent, SWT.NONE);
43 composite.setLayout(new FillLayout());
45 Table projectsTable = new Table(composite, SWT.CHECK | SWT.BORDER
46 | SWT.MULTI | SWT.FULL_SELECTION);
47 projectsTable.setHeaderVisible(false);
48 projectsTable.setLinesVisible(false);
49 projectsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
51 TableColumn tableColumn = new TableColumn(projectsTable, SWT.NONE);
52 tableColumn.setWidth(200);
53 tableColumn.setText(PHPPreferencesMessages
54 .getString("PHPEditorPreferencePageLibraryPage.project")); //$NON-NLS-1$
56 CheckboxTableViewer projectsTableViewer = new CheckboxTableViewer(
58 projectsTableViewer.addCheckStateListener(new ICheckStateListener() {
59 public void checkStateChanged(CheckStateChangedEvent event) {
60 projectCheckedUnchecked(event);
64 projectsTableViewer.setContentProvider(getContentProvider());
65 projectsTableViewer.setLabelProvider(getLabelProvider());
67 projectsTableViewer.setInput(getWorkspaceProjects());
68 projectsTableViewer.setCheckedElements(workingProject
69 .getReferencedProjects().toArray());
74 protected void projectCheckedUnchecked(CheckStateChangedEvent event) {
75 IProject checkEventProject = (IProject) event.getElement();
76 if (event.getChecked())
77 getWorkingProject().addLoadPathEntry(checkEventProject);
79 getWorkingProject().removeLoadPathEntry(checkEventProject);
82 protected JavaProject getWorkingProject() {
83 return workingProject;
86 protected List getWorkspaceProjects() {
87 IWorkspaceRoot root = PHPeclipsePlugin.getWorkspace().getRoot();
88 return Arrays.asList(root.getProjects());
91 protected ITableLabelProvider getLabelProvider() {
92 ITableLabelProvider labelProvider = new ITableLabelProvider() {
93 public Image getColumnImage(Object element, int columnIndex) {
94 IWorkbench workbench = WebUI.getDefault()
96 return workbench.getSharedImages().getImage(
97 SharedImages.IMG_OBJ_PROJECT);
100 public String getColumnText(Object element, int columnIndex) {
101 if (element instanceof IProject)
102 return ((IProject) element).getName();
104 return PHPPreferencesMessages
105 .getString("PHPEditorPreferencePageLibraryPage.elementNotIProject"); //$NON-NLS-1$
108 public void addListener(ILabelProviderListener listener) {
111 public void dispose() {
114 public boolean isLabelProperty(Object element, String property) {
118 public void removeListener(ILabelProviderListener listener) {
122 return labelProvider;
125 protected IContentProvider getContentProvider() {
126 IStructuredContentProvider contentProvider = new IStructuredContentProvider() {
127 protected List PHPEditorPreferencePages;
129 public Object[] getElements(Object inputElement) {
130 return PHPEditorPreferencePages.toArray();
133 public void dispose() {
136 public void inputChanged(Viewer viewer, Object oldInput,
138 PHPEditorPreferencePages = new ArrayList();
140 if (!(newInput instanceof List))
143 Iterator workspaceProjectsIterator = ((List) newInput)
145 while (workspaceProjectsIterator.hasNext()) {
146 Object anObject = workspaceProjectsIterator.next();
147 if (anObject instanceof IProject) {
148 IProject project = (IProject) anObject;
149 if (project.getName() != workingProject.getProject()
153 .hasNature(PHPeclipsePlugin.PHP_NATURE_ID))
154 PHPEditorPreferencePages.add(project);
155 } catch (CoreException e) {
163 return contentProvider;