001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.cheatsheet;
011:
012: import org.eclipse.jface.viewers.ISelection;
013: import org.eclipse.jface.viewers.IStructuredSelection;
014: import org.eclipse.pde.core.IModelChangedEvent;
015: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
016: import org.eclipse.pde.internal.ui.editor.PDEDetails;
017: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.ui.forms.IFormPart;
020: import org.eclipse.ui.forms.widgets.FormToolkit;
021:
022: /**
023: * CSAbstractDetails
024: *
025: */
026: public abstract class CSAbstractDetails extends PDEDetails implements
027: ICSDetails {
028:
029: private ICSMaster fMasterSection;
030:
031: private String fContextID;
032:
033: /**
034: *
035: */
036: public CSAbstractDetails(ICSMaster masterSection, String contextID) {
037: fMasterSection = masterSection;
038: fContextID = contextID;
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
043: */
044: public void createContents(Composite parent) {
045: configureParentLayout(parent);
046: createDetails(parent);
047: hookListeners();
048: }
049:
050: /**
051: * @param parent
052: */
053: private void configureParentLayout(Composite parent) {
054: parent.setLayout(FormLayoutFactory.createDetailsGridLayout(
055: false, 1));
056: }
057:
058: /**
059: * @param parent
060: */
061: public abstract void createDetails(Composite parent);
062:
063: /**
064: *
065: */
066: public abstract void updateFields();
067:
068: /**
069: *
070: */
071: public abstract void hookListeners();
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
075: */
076: public void selectionChanged(IFormPart part, ISelection selection) {
077: // NO-OP
078: // Children to override
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.pde.internal.ui.editor.IContextPart#fireSaveNeeded()
083: */
084: public void fireSaveNeeded() {
085: markDirty();
086: getPage().getPDEEditor().fireSaveNeeded(getContextId(), false);
087: }
088:
089: /* (non-Javadoc)
090: * @see org.eclipse.pde.internal.ui.editor.IContextPart#getContextId()
091: */
092: public String getContextId() {
093: return fContextID;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.eclipse.pde.internal.ui.editor.IContextPart#getPage()
098: */
099: 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 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: }
|