Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/OutlineConfiguration.java')
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/OutlineConfiguration.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/OutlineConfiguration.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/OutlineConfiguration.java
new file mode 100644
index 000000000..c667b0495
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/OutlineConfiguration.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * 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:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.editors;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jst.jsp.ui.views.contentoutline.JSPContentOutlineConfiguration;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+
+public class OutlineConfiguration extends JSPContentOutlineConfiguration {
+ private Object[] _selections = new Object[0];
+
+ public ISelection getSelection(TreeViewer viewer, ISelection selection) {
+ if ((viewer.getInput() instanceof IStructuredModel)
+ && (selection instanceof ITextSelection)) {
+ _selections = getSelectedObjects((IStructuredModel) viewer
+ .getInput(), (ITextSelection) selection);
+ if (_selections != null) {
+ return super.getSelection(viewer, new StructuredSelection(
+ _selections));
+ }
+ }
+ return super.getSelection(viewer, new StructuredSelection(_selections));
+ }
+
+ private Object[] getSelectedObjects(IStructuredModel model,
+ ITextSelection selection) {
+ Object[] selectedStructures = null;
+ if (model != null) {
+ IndexedRegion region = model
+ .getIndexedRegion(selection.getOffset());
+ int end = selection.getOffset() + selection.getLength();
+ if (region != null) {
+ if (end <= region.getEndOffset()) {
+ // single selection
+ selectedStructures = new Object[1];
+ selectedStructures[0] = region;
+ } else {
+ // multiple selection
+ int maxLength = model.getStructuredDocument().getLength();
+ List structures = new ArrayList(2);
+ while (region != null && region.getEndOffset() <= end
+ && region.getEndOffset() < maxLength) {
+ structures.add(region);
+ region = model
+ .getIndexedRegion(region.getEndOffset() + 1);
+ }
+ selectedStructures = structures.toArray();
+ }
+ }
+ }
+ if (selectedStructures == null) {
+ selectedStructures = new Object[0];
+ }
+ return selectedStructures;
+ }
+}

Back to the top