001: package org.eclipse.pde.internal.ui.editor.toc;
002:
003: import org.eclipse.jface.viewers.ISelection;
004: import org.eclipse.jface.viewers.IStructuredSelection;
005: import org.eclipse.pde.core.IModelChangedEvent;
006: import org.eclipse.pde.core.IModelChangedListener;
007: import org.eclipse.pde.internal.core.text.toc.Toc;
008: import org.eclipse.pde.internal.core.text.toc.TocAnchor;
009: import org.eclipse.pde.internal.core.text.toc.TocLink;
010: import org.eclipse.pde.internal.core.text.toc.TocTopic;
011: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
012: import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
013: import org.eclipse.pde.internal.ui.editor.PDESection;
014: import org.eclipse.pde.internal.ui.editor.toc.details.TocAbstractDetails;
015: import org.eclipse.pde.internal.ui.editor.toc.details.TocAnchorDetails;
016: import org.eclipse.pde.internal.ui.editor.toc.details.TocDetails;
017: import org.eclipse.pde.internal.ui.editor.toc.details.TocLinkDetails;
018: import org.eclipse.pde.internal.ui.editor.toc.details.TocTopicDetails;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.ui.forms.DetailsPart;
021: import org.eclipse.ui.forms.IDetailsPage;
022: import org.eclipse.ui.forms.IDetailsPageProvider;
023: import org.eclipse.ui.forms.IManagedForm;
024:
025: /**
026: * TODO: Comment
027: *
028: */
029: public class TocBlock extends PDEMasterDetailsBlock implements
030: IModelChangedListener, IDetailsPageProvider {
031:
032: private TocTreeSection fMasterSection;
033:
034: private TocAbstractDetails fDetails;
035:
036: private TocAbstractDetails fTopicDetails;
037:
038: private TocAnchorDetails fAnchorDetails;
039:
040: private TocLinkDetails fLinkDetails;
041:
042: /**TODO: Comment
043: * @param page
044: */
045: public TocBlock(PDEFormPage page) {
046: super (page);
047: }
048:
049: /* (non-Javadoc)
050: * @see org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock#createMasterSection(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
051: */
052: protected PDESection createMasterSection(IManagedForm managedForm,
053: Composite parent) {
054: fMasterSection = new TocTreeSection(getPage(), parent);
055: return fMasterSection;
056: }
057:
058: /* (non-Javadoc)
059: * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
060: */
061: protected void registerPages(DetailsPart detailsPart) {
062: // Only static pages to be defined. Do not cache pages
063: detailsPart.setPageLimit(0);
064: // Register static page: toc
065: fDetails = new TocDetails(fMasterSection);
066: detailsPart.registerPage(TocDetails.class, fDetails);
067: // Register static page: tocTopic
068: fTopicDetails = new TocTopicDetails(fMasterSection);
069: detailsPart.registerPage(TocTopicDetails.class, fTopicDetails);
070: // Register static page: tocAnchor
071: fAnchorDetails = new TocAnchorDetails(fMasterSection);
072: detailsPart
073: .registerPage(TocAnchorDetails.class, fAnchorDetails);
074: // Register static page: tocLink
075: fLinkDetails = new TocLinkDetails(fMasterSection);
076: detailsPart.registerPage(TocLinkDetails.class, fLinkDetails);
077: // Set this class as the page provider
078: detailsPart.setPageProvider(this );
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
083: */
084: public void modelChanged(IModelChangedEvent event) {
085: // Inform the master section
086: if (fMasterSection != null) {
087: fMasterSection.modelChanged(event);
088: }
089: }
090:
091: /* (non-Javadoc)
092: * @see org.eclipse.ui.forms.IDetailsPageProvider#getPage(java.lang.Object)
093: */
094: public IDetailsPage getPage(Object key) {
095: // No dynamic pages. Static pages already registered
096: return null;
097: }
098:
099: /* (non-Javadoc)
100: * @see org.eclipse.ui.forms.IDetailsPageProvider#getPageKey(java.lang.Object)
101: */
102: public Object getPageKey(Object object) {
103: ISelection selection = getSelection();
104: if (!(selection instanceof IStructuredSelection)
105: || ((IStructuredSelection) selection).size() > 1) {
106: return object.getClass();
107: }
108:
109: // Get static page key
110: if (object instanceof Toc) {
111: // Static page: toc
112: return TocDetails.class;
113: } else if (object instanceof TocTopic) {
114: // Static page: tocTopic
115: return TocTopicDetails.class;
116: } else if (object instanceof TocAnchor) {
117: // Static page: tocAnchor
118: return TocAnchorDetails.class;
119: } else if (object instanceof TocLink) {
120: // Static page: tocLink
121: return TocLinkDetails.class;
122: }
123:
124: // Should never reach here
125: return object.getClass();
126: }
127:
128: /**TODO: Comment
129: * @return
130: */
131: public ISelection getSelection() {
132: if (fMasterSection != null) {
133: return fMasterSection.getSelection();
134: }
135: return null;
136: }
137:
138: /**TODO: Comment
139: * @return
140: */
141: public TocTreeSection getMasterSection() {
142: return fMasterSection;
143: }
144: }
|