001: /*******************************************************************************
002: * Copyright (c) 2000, 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;
011:
012: import org.eclipse.jface.viewers.IStructuredSelection;
013: import org.eclipse.jface.viewers.TreeViewer;
014: import org.eclipse.pde.internal.ui.parts.StructuredViewerPart;
015: import org.eclipse.pde.internal.ui.parts.TreePart;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Button;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.ui.forms.widgets.FormToolkit;
020:
021: public abstract class TreeSection extends StructuredViewerSection {
022:
023: protected boolean fHandleDefaultButton = true;
024:
025: class PartAdapter extends TreePart {
026: public PartAdapter(String[] buttonLabels) {
027: super (buttonLabels);
028: }
029:
030: public void selectionChanged(IStructuredSelection selection) {
031: getManagedForm().fireSelectionChanged(TreeSection.this ,
032: selection);
033: TreeSection.this .selectionChanged(selection);
034: }
035:
036: public void handleDoubleClick(IStructuredSelection selection) {
037: TreeSection.this .handleDoubleClick(selection);
038: }
039:
040: public void buttonSelected(Button button, int index) {
041: TreeSection.this .buttonSelected(index);
042: if (fHandleDefaultButton)
043: button.getShell().setDefaultButton(null);
044: }
045:
046: protected void createButtons(Composite parent,
047: FormToolkit toolkit) {
048: super .createButtons(parent, toolkit);
049: enableButtons();
050: if (parent.getData("filtered") != null) { //$NON-NLS-1$
051: GridLayout layout = (GridLayout) fButtonContainer
052: .getLayout();
053: layout.marginHeight = 28;
054: }
055: }
056:
057: protected TreeViewer createTreeViewer(Composite parent,
058: int style) {
059: return TreeSection.this .createTreeViewer(parent, style);
060: }
061:
062: }
063:
064: /**
065: * Constructor for TableSection.
066: * @param formPage
067: */
068: public TreeSection(PDEFormPage formPage, Composite parent,
069: int style, String[] buttonLabels) {
070: super (formPage, parent, style, buttonLabels);
071: }
072:
073: protected StructuredViewerPart createViewerPart(
074: String[] buttonLabels) {
075: return new PartAdapter(buttonLabels);
076: }
077:
078: protected TreePart getTreePart() {
079: return (TreePart) fViewerPart;
080: }
081:
082: protected TreeViewer createTreeViewer(Composite parent, int style) {
083: return new TreeViewer(parent, style);
084: }
085:
086: protected void selectionChanged(IStructuredSelection selection) {
087: }
088:
089: /**
090: * Expands or collapsed selected node according to its current state
091: * @param selection
092: */
093: protected void handleDoubleClick(IStructuredSelection selection) {
094: TreeViewer viewer = (TreeViewer) fViewerPart.getViewer();
095: boolean expandedState = viewer.getExpandedState(selection
096: .getFirstElement());
097: viewer.setExpandedState(selection.getFirstElement(),
098: !expandedState);
099: }
100:
101: protected void enableButtons() {
102: }
103: }
|