KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > PDEMultiPageContentOutline


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.IStatusLineManager;
18 import org.eclipse.jface.action.IToolBarManager;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.ISelectionChangedListener;
21 import org.eclipse.jface.viewers.ISelectionProvider;
22 import org.eclipse.jface.viewers.SelectionChangedEvent;
23 import org.eclipse.pde.internal.ui.IHelpContextIds;
24 import org.eclipse.pde.internal.ui.IPreferenceConstants;
25 import org.eclipse.pde.internal.ui.PDEPlugin;
26 import org.eclipse.pde.internal.ui.PDEPluginImages;
27 import org.eclipse.pde.internal.ui.PDEUIMessages;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.events.FocusListener;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.ui.IActionBars;
33 import org.eclipse.ui.PlatformUI;
34 import org.eclipse.ui.part.Page;
35 import org.eclipse.ui.part.PageBook;
36 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
37
38 public class PDEMultiPageContentOutline extends Page
39     implements IContentOutlinePage, ISelectionProvider, ISelectionChangedListener, IPreferenceConstants {
40     private PageBook pagebook;
41     private ISelection selection;
42     private ArrayList JavaDoc listeners;
43     private ISortableContentOutlinePage currentPage;
44     private ISortableContentOutlinePage emptyPage;
45     private IActionBars actionBars;
46     private boolean sortingOn;
47     private PDEFormEditor editor;
48
49     public PDEMultiPageContentOutline(PDEFormEditor editor) {
50         this.editor=editor;
51         listeners = new ArrayList JavaDoc();
52         sortingOn= PDEPlugin.getDefault().getPreferenceStore().getBoolean("PDEMultiPageContentOutline.SortingAction.isChecked"); //$NON-NLS-1$
53

54     }
55     
56     public void addFocusListener(FocusListener listener) {
57     }
58     public void addSelectionChangedListener(ISelectionChangedListener listener) {
59         listeners.add(listener);
60     }
61     public void createControl(Composite parent) {
62         pagebook = new PageBook(parent, SWT.NONE);
63     }
64
65     public void dispose() {
66         if (pagebook != null && !pagebook.isDisposed())
67             pagebook.dispose();
68         if (emptyPage!=null) {
69             emptyPage.dispose();
70             emptyPage=null;
71         }
72         pagebook = null;
73         listeners = null;
74     }
75
76     public boolean isDisposed() {
77         return listeners==null;
78     }
79
80     public Control getControl() {
81         return pagebook;
82     }
83     public PageBook getPagebook() {
84         return pagebook;
85     }
86     public ISelection getSelection() {
87         return selection;
88     }
89     public void makeContributions(
90         IMenuManager menuManager,
91         IToolBarManager toolBarManager,
92         IStatusLineManager statusLineManager) {
93     }
94     public void removeFocusListener(FocusListener listener) {
95     }
96     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
97         listeners.remove(listener);
98     }
99     public void selectionChanged(SelectionChangedEvent event) {
100         setSelection(event.getSelection());
101     }
102
103     public void setActionBars(IActionBars actionBars) {
104         this.actionBars = actionBars;
105         registerToolbarActions(actionBars);
106         if (currentPage != null)
107             setPageActive(currentPage);
108
109     }
110     public IActionBars getActionBars() {
111         return actionBars;
112     }
113     public void setFocus() {
114         if (currentPage != null)
115             currentPage.setFocus();
116     }
117     private ISortableContentOutlinePage getEmptyPage() {
118         if (emptyPage==null)
119             emptyPage = new EmptyOutlinePage();
120         return emptyPage;
121     }
122     public void setPageActive(ISortableContentOutlinePage page) {
123         if (page==null) {
124             page = getEmptyPage();
125         }
126         if (currentPage != null) {
127             currentPage.removeSelectionChangedListener(this);
128         }
129         //page.init(getSite());
130
page.sort(sortingOn);
131         page.addSelectionChangedListener(this);
132         this.currentPage = page;
133         if (pagebook == null) {
134             // still not being made
135
return;
136         }
137         Control control = page.getControl();
138         if (control == null || control.isDisposed()) {
139             // first time
140
page.createControl(pagebook);
141             page.setActionBars(getActionBars());
142             control = page.getControl();
143         }
144         pagebook.showPage(control);
145         this.currentPage = page;
146     }
147     /**
148      * Set the selection.
149      */

150     public void setSelection(ISelection selection) {
151         this.selection =selection;
152         if (listeners == null)
153             return;
154         SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
155         for (int i=0; i<listeners.size(); i++) {
156             ((ISelectionChangedListener)listeners.get(i)).selectionChanged(e);
157         }
158     }
159     private void registerToolbarActions(IActionBars actionBars) {
160         
161         IToolBarManager toolBarManager= actionBars.getToolBarManager();
162         if (toolBarManager != null) {
163             toolBarManager.add(new ToggleLinkWithEditorAction(editor));
164             toolBarManager.add(new SortingAction());
165         }
166     }
167     
168     class SortingAction extends Action {
169         
170         public SortingAction() {
171             super();
172             PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IHelpContextIds.OUTLINE_SORT_ACTION);
173             setText(PDEUIMessages.PDEMultiPageContentOutline_SortingAction_label);
174             setImageDescriptor(PDEPluginImages.DESC_ALPHAB_SORT_CO);
175             setDisabledImageDescriptor(PDEPluginImages.DESC_ALPHAB_SORT_CO_DISABLED);
176             setToolTipText(PDEUIMessages.PDEMultiPageContentOutline_SortingAction_tooltip);
177             setDescription(PDEUIMessages.PDEMultiPageContentOutline_SortingAction_description);
178             setChecked(sortingOn);
179         }
180         
181         public void run() {
182             setChecked(isChecked());
183             valueChanged(isChecked());
184         }
185         private void valueChanged(final boolean on) {
186             sortingOn=on;
187             if(currentPage!=null)
188                 currentPage.sort(on);
189             PDEPlugin.getDefault().getPreferenceStore().setValue("PDEMultiPageContentOutline.SortingAction.isChecked", on); //$NON-NLS-1$
190
}
191         
192     }
193 }
194
Popular Tags