01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.parts;
11:
12: import org.eclipse.jface.viewers.StructuredViewer;
13: import org.eclipse.swt.graphics.Point;
14: import org.eclipse.swt.layout.GridData;
15: import org.eclipse.swt.widgets.Composite;
16: import org.eclipse.swt.widgets.Control;
17: import org.eclipse.ui.forms.widgets.FormToolkit;
18:
19: public abstract class StructuredViewerPart extends
20: SharedPartWithButtons {
21:
22: private StructuredViewer fViewer;
23:
24: private Point fMinSize;
25:
26: public StructuredViewerPart(String[] buttonLabels) {
27: super (buttonLabels);
28: }
29:
30: public StructuredViewer getViewer() {
31: return fViewer;
32: }
33:
34: public Control getControl() {
35: return fViewer.getControl();
36: }
37:
38: protected void createMainControl(Composite parent, int style,
39: int span, FormToolkit toolkit) {
40: fViewer = createStructuredViewer(parent, style, toolkit);
41: Control control = fViewer.getControl();
42: GridData gd = new GridData(GridData.FILL_BOTH);
43: gd.horizontalSpan = span;
44: control.setLayoutData(gd);
45: applyMinimumSize();
46: }
47:
48: public void setMinimumSize(int width, int height) {
49: fMinSize = new Point(width, height);
50: if (fViewer != null)
51: applyMinimumSize();
52: }
53:
54: private void applyMinimumSize() {
55: if (fMinSize != null) {
56: GridData gd = (GridData) fViewer.getControl()
57: .getLayoutData();
58: gd.widthHint = fMinSize.x;
59: gd.heightHint = fMinSize.y;
60: }
61: }
62:
63: protected void updateEnabledState() {
64: getControl().setEnabled(isEnabled());
65: super .updateEnabledState();
66: }
67:
68: protected abstract StructuredViewer createStructuredViewer(
69: Composite parent, int style, FormToolkit toolkit);
70: }
|