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.simple;
011:
012: import org.eclipse.jface.viewers.ISelection;
013: import org.eclipse.pde.core.IModelChangedEvent;
014: import org.eclipse.pde.core.IModelChangedListener;
015: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
016: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro;
017: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem;
018: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem;
019: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
020: import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
021: import org.eclipse.pde.internal.ui.editor.PDESection;
022: import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
023: import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSDetails;
024: import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSIntroDetails;
025: import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSItemDetails;
026: import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.SimpleCSSubItemDetails;
027: import org.eclipse.swt.widgets.Composite;
028: import org.eclipse.ui.forms.DetailsPart;
029: import org.eclipse.ui.forms.IDetailsPage;
030: import org.eclipse.ui.forms.IDetailsPageProvider;
031: import org.eclipse.ui.forms.IManagedForm;
032:
033: /**
034: * SimpleCSBlock
035: *
036: */
037: public class SimpleCSBlock extends PDEMasterDetailsBlock implements
038: IDetailsPageProvider, IModelChangedListener {
039:
040: private SimpleCSMasterTreeSection fMasterSection;
041:
042: private SimpleCSItemDetails fItemDetails;
043:
044: private SimpleCSSubItemDetails fSubItemDetails;
045:
046: private SimpleCSDetails fCheatSheetDetails;
047:
048: private SimpleCSIntroDetails fIntroDetails;
049:
050: /**
051: * @param page
052: */
053: public SimpleCSBlock(PDEFormPage page) {
054: super (page);
055: }
056:
057: /* (non-Javadoc)
058: * @see org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock#createMasterSection(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
059: */
060: protected PDESection createMasterSection(IManagedForm managedForm,
061: Composite parent) {
062: fMasterSection = new SimpleCSMasterTreeSection(getPage(),
063: parent);
064: return fMasterSection;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
069: */
070: protected void registerPages(DetailsPart detailsPart) {
071: // Only static pages to be defined. Do not cache pages
072: detailsPart.setPageLimit(0);
073: // Register static page: item
074: fItemDetails = new SimpleCSItemDetails(fMasterSection);
075: detailsPart.registerPage(SimpleCSItemDetails.class,
076: fItemDetails);
077: // Register static page: subitem
078: fSubItemDetails = new SimpleCSSubItemDetails(fMasterSection);
079: detailsPart.registerPage(SimpleCSSubItemDetails.class,
080: fSubItemDetails);
081: // Register static page: cheatsheet
082: fCheatSheetDetails = new SimpleCSDetails(fMasterSection);
083: detailsPart.registerPage(SimpleCSDetails.class,
084: fCheatSheetDetails);
085: // Register static page: intro
086: fIntroDetails = new SimpleCSIntroDetails(fMasterSection);
087: detailsPart.registerPage(SimpleCSIntroDetails.class,
088: fIntroDetails);
089: // Set this class as the page provider
090: detailsPart.setPageProvider(this );
091: }
092:
093: /* (non-Javadoc)
094: * @see org.eclipse.ui.forms.IDetailsPageProvider#getPageKey(java.lang.Object)
095: */
096: public Object getPageKey(Object object) {
097: // Get static page key
098: if (object instanceof ISimpleCSItem) {
099: // Static page: item
100: return SimpleCSItemDetails.class;
101: } else if (object instanceof ISimpleCSSubItem) {
102: // Static page: subitem
103: return SimpleCSSubItemDetails.class;
104: } else if (object instanceof ISimpleCS) {
105: // Static page: cheatsheet
106: return SimpleCSDetails.class;
107: } else if (object instanceof ISimpleCSIntro) {
108: // Static page: intro
109: return SimpleCSIntroDetails.class;
110: }
111: // Should never reach here
112: return object.getClass();
113: }
114:
115: /* (non-Javadoc)
116: * @see org.eclipse.ui.forms.IDetailsPageProvider#getPage(java.lang.Object)
117: */
118: public IDetailsPage getPage(Object key) {
119: // No dynamic pages. Static pages already registered
120: return null;
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
125: */
126: public void modelChanged(IModelChangedEvent event) {
127: // Inform the master section
128: if (fMasterSection != null) {
129: fMasterSection.modelChanged(event);
130: }
131: // Inform the details section
132: // Unnecessary
133: //if (fCurrentDetailsSection != null) {
134: // fCurrentDetailsSection.modelChanged(event);
135: //}
136: }
137:
138: /**
139: * @return
140: */
141: public ICSMaster getMastersSection() {
142: return fMasterSection;
143: }
144:
145: /**
146: * @return
147: */
148: public ISelection getSelection() {
149: if (fMasterSection != null) {
150: return fMasterSection.getSelection();
151: }
152: return null;
153: }
154:
155: }
|