001: /*******************************************************************************
002: * Copyright (c) 2000, 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.jface.viewers.ISelection;
013: import org.eclipse.pde.core.IModelChangedEvent;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.ui.forms.IFormPart;
016:
017: /**
018: * Wrapper for PDESections, implemens IDetailsPage for use in MasterDetailsBlock
019: */
020: public abstract class PDEDetailsSections extends PDEDetails {
021: private PDESection sections[];
022:
023: protected abstract PDESection[] createSections(PDEFormPage page,
024: Composite parent);
025:
026: /*
027: * (non-Javadoc)
028: *
029: * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
030: */
031: public void createContents(Composite parent) {
032: sections = createSections(getPage(), parent);
033: parent.setLayout(FormLayoutFactory.createDetailsGridLayout(
034: false, 1));
035: for (int i = 0; i < sections.length; i++) {
036: getManagedForm().addPart(sections[i]);
037: }
038: }
039:
040: public void dispose() {
041: for (int i = 0; i < sections.length; i++) {
042: sections[i].dispose();
043: }
044: }
045:
046: public void fireSaveNeeded() {
047: markDirty();
048: getPage().getPDEEditor().fireSaveNeeded(getContextId(), false);
049: }
050:
051: public abstract String getContextId();
052:
053: public PDEFormPage getPage() {
054: return (PDEFormPage) getManagedForm().getContainer();
055: }
056:
057: /*
058: * (non-Javadoc)
059: *
060: * @see org.eclipse.ui.forms.AbstractFormPart#isDirty()
061: */
062: public boolean isDirty() {
063: for (int i = 0; i < sections.length; i++) {
064: if (sections[i].isDirty()) {
065: return true;
066: }
067: }
068: return super .isDirty();
069: }
070:
071: public boolean isEditable() {
072: return getPage().getPDEEditor().getAggregateModel()
073: .isEditable();
074: }
075:
076: /*
077: * (non-Javadoc)
078: *
079: * @see org.eclipse.ui.forms.AbstractFormPart#isStale()
080: */
081: public boolean isStale() {
082: for (int i = 0; i < sections.length; i++) {
083: if (sections[i].isStale()) {
084: return true;
085: }
086: }
087: return super .isStale();
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
094: */
095: public void modelChanged(IModelChangedEvent event) {
096: }
097:
098: /*
099: * (non-Javadoc)
100: *
101: * @see org.eclipse.ui.forms.IDetailsPage#inputChanged(org.eclipse.jface.viewers.IStructuredSelection)
102: */
103: public void selectionChanged(IFormPart masterPart,
104: ISelection selection) {
105: }
106:
107: /*
108: * (non-Javadoc)
109: *
110: * @see org.eclipse.ui.forms.IDetailsPage#setFocus()
111: */
112: public void setFocus() {
113: if (sections.length > 0) {
114: sections[0].setFocus();
115: }
116: }
117: }
|