001: /*******************************************************************************
002: * Copyright (c) 2003, 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;
011:
012: import org.eclipse.core.resources.IProject;
013: import org.eclipse.core.runtime.IAdaptable;
014: import org.eclipse.jface.viewers.ISelection;
015: import org.eclipse.pde.core.IBaseModel;
016: import org.eclipse.pde.core.IModelChangedEvent;
017: import org.eclipse.pde.core.IModelChangedListener;
018: import org.eclipse.swt.dnd.Clipboard;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.ui.forms.SectionPart;
021: import org.eclipse.ui.forms.widgets.ExpandableComposite;
022: import org.eclipse.ui.forms.widgets.FormToolkit;
023: import org.eclipse.ui.forms.widgets.Section;
024:
025: public abstract class PDESection extends SectionPart implements
026: IModelChangedListener, IContextPart, IAdaptable {
027:
028: private PDEFormPage fPage;
029:
030: public PDESection(PDEFormPage page, Composite parent, int style) {
031: this (page, parent, style, true);
032: }
033:
034: public PDESection(PDEFormPage page, Composite parent, int style,
035: boolean titleBar) {
036: super (parent, page.getManagedForm().getToolkit(),
037: titleBar ? (ExpandableComposite.TITLE_BAR | style)
038: : style);
039: fPage = page;
040: initialize(page.getManagedForm());
041: getSection().clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
042: getSection().setData("part", this ); //$NON-NLS-1$
043: }
044:
045: protected abstract void createClient(Section section,
046: FormToolkit toolkit);
047:
048: public PDEFormPage getPage() {
049: return fPage;
050: }
051:
052: protected IProject getProject() {
053: return fPage.getPDEEditor().getCommonProject();
054: }
055:
056: public boolean doGlobalAction(String actionId) {
057: return false;
058: }
059:
060: public void modelChanged(IModelChangedEvent e) {
061: if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED)
062: markStale();
063: }
064:
065: public String getContextId() {
066: return null;
067: }
068:
069: public void fireSaveNeeded() {
070: markDirty();
071: if (getContextId() != null)
072: getPage().getPDEEditor().fireSaveNeeded(getContextId(),
073: false);
074: }
075:
076: public boolean isEditable() {
077: // getAggregateModel() can (though never should) return null
078: IBaseModel model = getPage().getPDEEditor().getAggregateModel();
079: return model == null ? false : model.isEditable();
080: }
081:
082: /**
083: * @param selection
084: * @return
085: */
086: public boolean canCopy(ISelection selection) {
087: // Sub-classes to override
088: return false;
089: }
090:
091: /**
092: * @param selection
093: * @return
094: */
095: public boolean canCut(ISelection selection) {
096: // Sub-classes to override
097: return false;
098: }
099:
100: public boolean canPaste(Clipboard clipboard) {
101: return false;
102: }
103:
104: public void cancelEdit() {
105: super .refresh();
106: }
107:
108: public Object getAdapter(Class adapter) {
109: return null;
110: }
111: }
|