001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.schema;
011:
012: import org.eclipse.jface.viewers.ILabelProvider;
013: import org.eclipse.pde.core.IModelChangedEvent;
014: import org.eclipse.pde.internal.core.ischema.IDocumentSection;
015: import org.eclipse.pde.internal.core.ischema.ISchema;
016: import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
017: import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
018: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
019: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
020: import org.eclipse.pde.internal.core.ischema.ISchemaType;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
023: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
024:
025: public class SchemaFormOutlinePage extends FormOutlinePage {
026: private Object[] fTopics;
027:
028: public Object[] getChildren(Object parent) {
029: ISchema schema = (ISchema) fEditor.getAggregateModel();
030: if (schema != null && schema.isValid()) {
031: if (parent instanceof SchemaFormPage) {
032: return getMarkup();
033: }
034: if (parent instanceof ISchemaElement) {
035: return getAttributes((ISchemaElement) parent);
036: }
037: if (parent instanceof SchemaOverviewPage) {
038: return getTopics();
039: }
040: }
041: return super .getChildren(parent);
042: }
043:
044: class SchemaLabelProvider extends BasicLabelProvider {
045: public String getText(Object obj) {
046: String label = getObjectLabel(obj);
047: return (label == null) ? super .getText(obj) : label;
048: }
049: }
050:
051: public SchemaFormOutlinePage(PDEFormEditor editor) {
052: super (editor);
053: }
054:
055: public ILabelProvider createLabelProvider() {
056: return new SchemaLabelProvider();
057: }
058:
059: protected Object[] createTopics() {
060: ISchema schema = (ISchema) fEditor.getAggregateModel();
061: IDocumentSection[] sections = schema.getDocumentSections();
062: Object[] result = new Object[sections.length + 1];
063: result[0] = schema;
064: for (int i = 1; i <= sections.length; i++) {
065: result[i] = sections[i - 1];
066: }
067: return result;
068: }
069:
070: private Object[] getAttributes(ISchemaElement element) {
071: ISchemaType type = element.getType();
072: if (type instanceof ISchemaComplexType) {
073: return ((ISchemaComplexType) type).getAttributes();
074: }
075: return new Object[0];
076: }
077:
078: private Object[] getMarkup() {
079: ISchema schema = (ISchema) fEditor.getAggregateModel();
080: return schema.getElements();
081: }
082:
083: protected String getObjectLabel(Object obj) {
084: if (obj instanceof ISchema) {
085: return PDEUIMessages.SchemaEditor_topic_overview;
086: }
087: if (obj instanceof IDocumentSection) {
088: IDocumentSection section = (IDocumentSection) obj;
089: String sectionId = section.getSectionId();
090: if (sectionId.equals(IDocumentSection.EXAMPLES))
091: return PDEUIMessages.SchemaEditor_topic_examples;
092: if (sectionId.equals(IDocumentSection.SINCE))
093: return PDEUIMessages.SchemaEditor_topic_since;
094: if (sectionId.equals(IDocumentSection.IMPLEMENTATION))
095: return PDEUIMessages.SchemaEditor_topic_implementation;
096: if (sectionId.equals(IDocumentSection.API_INFO))
097: return PDEUIMessages.SchemaEditor_topic_api;
098: if (sectionId.equals(IDocumentSection.COPYRIGHT))
099: return PDEUIMessages.SchemaEditor_topic_copyright;
100: }
101: return null;
102: }
103:
104: Object[] getTopics() {
105: if (fTopics == null) {
106: fTopics = createTopics();
107: }
108: return fTopics;
109: }
110:
111: protected String getParentPageId(Object item) {
112: if (item instanceof ISchemaElement
113: || item instanceof ISchemaAttribute)
114: return SchemaFormPage.PAGE_ID;
115: if (item instanceof IDocumentSection || item instanceof ISchema)
116: return SchemaOverviewPage.PAGE_ID;
117: return super .getParentPageId(item);
118: }
119:
120: public void modelChanged(IModelChangedEvent event) {
121: if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
122: fTopics = null;
123: fTreeViewer.refresh();
124: return;
125: }
126: Object object = event.getChangedObjects()[0];
127: if (event.getChangeType() == IModelChangedEvent.CHANGE) {
128: fTreeViewer.update(object, null);
129: } else {
130: // find the parent
131: Object parent = null;
132: if (object instanceof ISchemaObject) {
133: parent = ((ISchemaObject) object).getParent();
134: }
135: if (parent != null) {
136: fTreeViewer.refresh(parent);
137: fTreeViewer.expandToLevel(parent, 2);
138: } else {
139: fTreeViewer.refresh();
140: fTreeViewer.expandAll();
141: }
142: }
143: }
144: }
|