KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > comp > CompCSPage


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.comp;
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.comp.ICompCS;
19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
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  * CompCSPage
37  *
38  */

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

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

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

57     protected String JavaDoc getHelpResource() {
58         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/composite_cs_editor/editor.htm"; //$NON-NLS-1$
59
}
60     
61     // TODO: MP: LOW: CompCS: Clean-up and reuse externalized strings
62

63     /* (non-Javadoc)
64      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
65      */

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

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

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

159     public ISelection getSelection() {
160         return fBlock.getSelection();
161     }
162     
163     /**
164      * @param event
165      */

166     private void handleModelEventWorldChanged(IModelChangedEvent event) {
167         
168         Object JavaDoc[] objects = event.getChangedObjects();
169         ICompCSObject object = (ICompCSObject) objects[0];
170         if (object == null) {
171             // Ignore
172
return;
173         } else if (object.getType() == ICompCSConstants.TYPE_COMPOSITE_CHEATSHEET) {
174             String JavaDoc newValue = ((ICompCS)object).getFieldName();
175             // Update page title
176
getManagedForm().getForm().setText(
177                     PDETextHelper.translateReadText(newValue));
178         }
179     }
180     
181     /**
182      * @return
183      */

184     public PDEMasterDetailsBlock getBlock() {
185         return fBlock;
186     }
187     
188 }
189
Popular Tags