KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > SimpleCSBlock


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple;
13
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.pde.core.IModelChangedEvent;
16 import org.eclipse.pde.core.IModelChangedListener;
17 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro;
19 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem;
20 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem;
21 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
22 import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
23 import org.eclipse.pde.internal.ui.editor.PDESection;
24 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
25 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSDetails;
26 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSIntroDetails;
27 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSItemDetails;
28 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSSubItemDetails;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.ui.forms.DetailsPart;
31 import org.eclipse.ui.forms.IDetailsPage;
32 import org.eclipse.ui.forms.IDetailsPageProvider;
33 import org.eclipse.ui.forms.IManagedForm;
34
35 /**
36  * SimpleCSBlock
37  *
38  */

39 public class SimpleCSBlock extends PDEMasterDetailsBlock implements
40         IDetailsPageProvider, IModelChangedListener {
41
42     private SimpleCSMasterTreeSection fMasterSection;
43
44     private SimpleCSItemDetails fItemDetails;
45     
46     private SimpleCSSubItemDetails fSubItemDetails;
47     
48     private SimpleCSDetails fCheatSheetDetails;
49     
50     private SimpleCSIntroDetails fIntroDetails;
51     
52     /**
53      * @param page
54      */

55     public SimpleCSBlock(PDEFormPage page) {
56         super(page);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock#createMasterSection(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
61      */

62     protected PDESection createMasterSection(IManagedForm managedForm,
63             Composite parent) {
64         fMasterSection = new SimpleCSMasterTreeSection(getPage(), parent);
65         return fMasterSection;
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
70      */

71     protected void registerPages(DetailsPart detailsPart) {
72         // Only static pages to be defined. Do not cache pages
73
detailsPart.setPageLimit(0);
74         // Register static page: item
75
fItemDetails = new SimpleCSItemDetails(fMasterSection);
76         detailsPart.registerPage(SimpleCSItemDetails.class, fItemDetails);
77         // Register static page: subitem
78
fSubItemDetails = new SimpleCSSubItemDetails(fMasterSection);
79         detailsPart.registerPage(SimpleCSSubItemDetails.class, fSubItemDetails);
80         // Register static page: cheatsheet
81
fCheatSheetDetails = new SimpleCSDetails(fMasterSection);
82         detailsPart.registerPage(SimpleCSDetails.class, fCheatSheetDetails);
83         // Register static page: intro
84
fIntroDetails = new SimpleCSIntroDetails(fMasterSection);
85         detailsPart.registerPage(SimpleCSIntroDetails.class, fIntroDetails);
86         // Set this class as the page provider
87
detailsPart.setPageProvider(this);
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.ui.forms.IDetailsPageProvider#getPageKey(java.lang.Object)
92      */

93     public Object JavaDoc getPageKey(Object JavaDoc object) {
94         // Get static page key
95
if (object instanceof ISimpleCSItem) {
96             // Static page: item
97
return SimpleCSItemDetails.class;
98         } else if (object instanceof ISimpleCSSubItem) {
99             // Static page: subitem
100
return SimpleCSSubItemDetails.class;
101         } else if (object instanceof ISimpleCS) {
102             // Static page: cheatsheet
103
return SimpleCSDetails.class;
104         } else if (object instanceof ISimpleCSIntro) {
105             // Static page: intro
106
return SimpleCSIntroDetails.class;
107         }
108         // Should never reach here
109
return object.getClass();
110     }
111     
112     /* (non-Javadoc)
113      * @see org.eclipse.ui.forms.IDetailsPageProvider#getPage(java.lang.Object)
114      */

115     public IDetailsPage getPage(Object JavaDoc key) {
116         // No dynamic pages. Static pages already registered
117
return null;
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
122      */

123     public void modelChanged(IModelChangedEvent event) {
124         // Inform the master section
125
if (fMasterSection != null) {
126             fMasterSection.modelChanged(event);
127         }
128         // Inform the details section
129
// Unnecessary
130
//if (fCurrentDetailsSection != null) {
131
// fCurrentDetailsSection.modelChanged(event);
132
//}
133
}
134     
135     /**
136      * @return
137      */

138     public ICSMaster getMastersSection() {
139         return fMasterSection;
140     }
141
142     /**
143      * @return
144      */

145     public ISelection getSelection() {
146         if (fMasterSection != null) {
147             return fMasterSection.getSelection();
148         }
149         return null;
150     }
151     
152 }
153
Popular Tags