Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/outline/SpecfileContentProvider.java')
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/outline/SpecfileContentProvider.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/outline/SpecfileContentProvider.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/outline/SpecfileContentProvider.java
new file mode 100644
index 0000000000..2d5ca3b421
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/outline/SpecfileContentProvider.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.rpm.ui.editor.outline;
+
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor;
+import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
+import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage;
+import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class SpecfileContentProvider implements ITreeContentProvider {
+
+ private IDocumentProvider documentProvider;
+ private Specfile specfile;
+ private SpecfileEditor specEditor;
+ protected final static String SECTION_POSITIONS = "section_positions"; //$NON-NLS-1$
+ protected IPositionUpdater positionUpdater = new DefaultPositionUpdater(SECTION_POSITIONS);
+
+ public SpecfileContentProvider(ITextEditor editor) {
+ if (editor instanceof SpecfileEditor) {
+ specEditor = (SpecfileEditor) editor;
+ specfile = specEditor.getSpecfile();
+ }
+ this.documentProvider = editor.getDocumentProvider();
+ }
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (oldInput != null)
+ {
+ IDocument document = documentProvider.getDocument(oldInput);
+ if (document != null)
+ {
+ try
+ {
+ document.removePositionCategory(SECTION_POSITIONS);
+ }
+ catch (BadPositionCategoryException x)
+ {
+ }
+ document.removePositionUpdater(positionUpdater);
+ }
+ }
+
+ if (newInput != null)
+ {
+ IDocument document = documentProvider.getDocument(newInput);
+ if (document != null)
+ {
+ document.addPositionCategory(SECTION_POSITIONS);
+ document.addPositionUpdater(positionUpdater);
+ if (specEditor != null)
+ specfile = specEditor.getSpecfile();
+ }
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement == specfile) {
+ Object[] elms = new Object[1 + 1 + specfile.getSections().size()];
+ elms[0] = specfile.getPreamble();
+ elms[1] = specfile.getPackages();
+ Object[] sections = specfile.getSections().toArray();
+ for (int i = 0; i < sections.length; i++) {
+ elms[i + 2] = sections[i];
+ }
+ return elms;
+ } else if (parentElement instanceof SpecfilePackageContainer) {
+ return ((SpecfilePackageContainer) parentElement).getPackages();
+ } else if (parentElement instanceof SpecfilePackage) {
+ return ((SpecfilePackage) parentElement).getSections();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element == specfile) {
+ return true;
+ } else if (element instanceof SpecfilePackageContainer) {
+ return ((SpecfilePackageContainer) element).hasChildren();
+ } else if (element instanceof SpecfilePackage) {
+ return ((SpecfilePackage) element).hasChildren();
+ }
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return this.getChildren(specfile);
+ }
+
+}

Back to the top