KickJava   Java API By Example, From Geeks To Geeks.

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


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;
13
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.pde.core.IModelChangedEvent;
17 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
18 import org.eclipse.pde.internal.ui.editor.PDEDetails;
19 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.ui.forms.IFormPart;
22 import org.eclipse.ui.forms.widgets.FormToolkit;
23
24 /**
25  * CSAbstractDetails
26  *
27  */

28 public abstract class CSAbstractDetails extends PDEDetails implements ICSDetails {
29
30     private ICSMaster fMasterSection;
31     
32     private String JavaDoc fContextID;
33     
34     /**
35      *
36      */

37     public CSAbstractDetails(ICSMaster masterSection, String JavaDoc contextID) {
38         fMasterSection = masterSection;
39         fContextID = contextID;
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
44      */

45     public void createContents(Composite parent) {
46         configureParentLayout(parent);
47         createDetails(parent);
48         hookListeners();
49     }
50
51     /**
52      * @param parent
53      */

54     private void configureParentLayout(Composite parent) {
55         parent.setLayout(FormLayoutFactory.createDetailsGridLayout(false, 1));
56     }
57     
58     /**
59      * @param parent
60      */

61     public abstract void createDetails(Composite parent);
62     
63     /**
64      *
65      */

66     public abstract void updateFields();
67     
68     /**
69      *
70      */

71     public abstract void hookListeners();
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
75      */

76     public void selectionChanged(IFormPart part, ISelection selection) {
77         // NO-OP
78
// Children to override
79
}
80
81     /* (non-Javadoc)
82      * @see org.eclipse.pde.internal.ui.editor.IContextPart#fireSaveNeeded()
83      */

84     public void fireSaveNeeded() {
85         markDirty();
86         getPage().getPDEEditor().fireSaveNeeded(getContextId(), false);
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.pde.internal.ui.editor.IContextPart#getContextId()
91      */

92     public String JavaDoc getContextId() {
93         return fContextID;
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.pde.internal.ui.editor.IContextPart#getPage()
98      */

99     public PDEFormPage getPage() {
100         return (PDEFormPage)getManagedForm().getContainer();
101     }
102
103     /* (non-Javadoc)
104      * @see org.eclipse.pde.internal.ui.editor.IContextPart#isEditable()
105      */

106     public boolean isEditable() {
107         return fMasterSection.isEditable();
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
112      */

113     public void modelChanged(IModelChangedEvent event) {
114         // NO-OP
115
}
116     
117     /**
118      * @return
119      */

120     public boolean isEditableElement() {
121         return fMasterSection.isEditable();
122     }
123     
124     /**
125      * @return
126      */

127     public FormToolkit getToolkit() {
128         return getManagedForm().getToolkit();
129     }
130     
131     /**
132      * @return
133      */

134     public ICSMaster getMasterSection() {
135         return fMasterSection;
136     }
137     
138     /**
139      * @param selection
140      * @return
141      */

142     protected Object JavaDoc getFirstSelectedObject(ISelection selection) {
143         // Get the structured selection (obtained from the master tree viewer)
144
IStructuredSelection structuredSel = ((IStructuredSelection)selection);
145         // Ensure we have a selection
146
if (structuredSel == null) {
147             return null;
148         }
149         return structuredSel.getFirstElement();
150     }
151     
152 }
153
Popular Tags