KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > parts > StructuredViewerPart


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.parts;
12
13 import org.eclipse.jface.viewers.StructuredViewer;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.ui.forms.widgets.FormToolkit;
19
20 public abstract class StructuredViewerPart extends SharedPartWithButtons {
21
22     private StructuredViewer fViewer;
23
24     private Point fMinSize;
25
26     public StructuredViewerPart(String JavaDoc[] 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, int span, FormToolkit toolkit) {
39         fViewer = createStructuredViewer(parent, style, toolkit);
40         Control control = fViewer.getControl();
41         GridData gd = new GridData(GridData.FILL_BOTH);
42         gd.horizontalSpan = span;
43         control.setLayoutData(gd);
44         applyMinimumSize();
45     }
46
47     public void setMinimumSize(int width, int height) {
48         fMinSize = new Point(width, height);
49         if (fViewer != null)
50             applyMinimumSize();
51     }
52
53     private void applyMinimumSize() {
54         if (fMinSize != null) {
55             GridData gd = (GridData) fViewer.getControl().getLayoutData();
56             gd.widthHint = fMinSize.x;
57             gd.heightHint = fMinSize.y;
58         }
59     }
60
61     protected void updateEnabledState() {
62         getControl().setEnabled(isEnabled());
63         super.updateEnabledState();
64     }
65
66     protected abstract StructuredViewer createStructuredViewer(Composite parent,
67             int style, FormToolkit toolkit);
68 }
69
Popular Tags