KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractModel;
18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
19 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
20 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
22 import org.eclipse.pde.internal.core.util.PDETextHelper;
23 import org.eclipse.pde.internal.ui.IHelpContextIds;
24 import org.eclipse.pde.internal.ui.IPDEUIConstants;
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.pde.internal.ui.editor.PDEMasterDetailsBlock;
29 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractPage;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.forms.IManagedForm;
32 import org.eclipse.ui.forms.editor.FormEditor;
33 import org.eclipse.ui.forms.widgets.ScrolledForm;
34
35 /**
36  * SimpleCSPage
37  *
38  */

39 public class SimpleCSPage extends CSAbstractPage implements IModelChangedListener {
40
41     public static final String JavaDoc PAGE_ID = "simpleCSPage"; //$NON-NLS-1$
42

43     private SimpleCSBlock fBlock;
44     
45     /**
46      * @param editor
47      */

48     public SimpleCSPage(FormEditor editor) {
49         super(editor, PAGE_ID, PDEUIMessages.SimpleCSPage_0);
50         fBlock = new SimpleCSBlock(this);
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
55      */

56     protected String JavaDoc getHelpResource() {
57         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/simple_cs_editor/editor.htm"; //$NON-NLS-1$
58
}
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
62      */

63     protected void createFormContent(IManagedForm managedForm) {
64         // Bug: Two veritical scrollbars appear when resizing the editor
65
// vertically
66
// Note: Scrolled form #1 created here
67
ScrolledForm form = managedForm.getForm();
68         // Set page title
69
ISimpleCSModel model = (ISimpleCSModel)getModel();
70         // Ensure the model was loaded properly
71
if ((model == null) ||
72                 (model.isLoaded() == false)) {
73             Exception JavaDoc e = null;
74             if (model instanceof AbstractModel) {
75                 e = ((AbstractModel)model).getException();
76             }
77             // Create a formatted error page
78
createFormErrorContent(managedForm,
79                     PDEUIMessages.SimpleCSPage_msgCheatSheetLoadFailure,
80                     PDEUIMessages.SimpleCSPage_msgCheatSheetParsingFailure,
81                     e);
82             return;
83         }
84         // Create the register cheat sheet link in the form title area
85
createUIFormTitleRegisterCSLink(managedForm, model);
86         // Create the rest of the actions in the form title area
87
super.createFormContent(managedForm);
88         // Form image
89
form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
90                 PDEPluginImages.DESC_CHEATSHEET_OBJ));
91         // Form title
92
String JavaDoc title = PDETextHelper.translateReadText(model.getSimpleCS()
93                 .getTitle());
94         if (title.length() > 0) {
95             form.setText(title);
96         } else {
97             form.setText(PDEUIMessages.SimpleCSPage_0);
98         }
99         // Create the masters details block
100
// Note: Scrolled form #2 created here
101
fBlock.createContent(managedForm);
102         // Force the selection in the masters tree section to load the
103
// proper details section
104
fBlock.getMastersSection().fireSelection();
105         // Register this page to be informed of model change events
106
model.addModelChangedListener(this);
107         // Set context-sensitive help
108
PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(),
109                 IHelpContextIds.SIMPLE_CS_EDITOR);
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#dispose()
114      */

115     public void dispose() {
116         
117         ISimpleCSModel simpleCSModel = (ISimpleCSModel)getModel();
118         if (simpleCSModel != null) {
119             simpleCSModel.removeModelChangedListener(this);
120         }
121         super.dispose();
122     }
123
124     /* (non-Javadoc)
125      * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
126      */

127     public void modelChanged(IModelChangedEvent event) {
128         
129         if (event.getChangeType() == IModelChangedEvent.CHANGE) {
130             Object JavaDoc[] objects = event.getChangedObjects();
131             ISimpleCSObject object = (ISimpleCSObject) objects[0];
132             if (object == null) {
133                 // Ignore
134
} else if (object.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
135                 String JavaDoc changeProperty = event.getChangedProperty();
136                 if ((changeProperty != null)
137                         && changeProperty
138                                 .equals(ISimpleCSConstants.ATTRIBUTE_TITLE)) {
139                     // Has to be a String if the property is a title
140
// Update the form page title
141
getManagedForm().getForm().setText(
142                             PDETextHelper.translateReadText((String JavaDoc) event
143                                     .getNewValue()));
144                 }
145             }
146         } else if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
147             handleModelEventWorldChanged(event);
148         }
149         // Inform the block
150
fBlock.modelChanged(event);
151     }
152
153     /**
154      * @param event
155      */

156     private void handleModelEventWorldChanged(IModelChangedEvent event) {
157         
158         Object JavaDoc[] objects = event.getChangedObjects();
159         ISimpleCSObject object = (ISimpleCSObject) objects[0];
160         if (object == null) {
161             // Ignore
162
return;
163         } else if (object.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
164             String JavaDoc newValue = ((ISimpleCS)object).getTitle();
165             // Update page title
166
getManagedForm().getForm().setText(
167                     PDETextHelper.translateReadText(newValue));
168         }
169     }
170
171     /**
172      * @return
173      */

174     public ISelection getSelection() {
175         return fBlock.getSelection();
176     }
177
178     /**
179      * @return
180      */

181     public PDEMasterDetailsBlock getBlock() {
182         return fBlock;
183     }
184     
185 }
186
Popular Tags