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.action.IAction;
013: import org.eclipse.jface.viewers.IStructuredSelection;
014: import org.eclipse.osgi.util.NLS;
015: import org.eclipse.pde.internal.ui.PDEUIMessages;
016: import org.eclipse.pde.internal.ui.parts.EditableTablePart;
017: import org.eclipse.pde.internal.ui.parts.StructuredViewerPart;
018: import org.eclipse.swt.events.PaintEvent;
019: import org.eclipse.swt.events.PaintListener;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.widgets.Button;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.ui.forms.IFormColors;
025: import org.eclipse.ui.forms.widgets.FormToolkit;
026:
027: public abstract class TableSection extends StructuredViewerSection {
028: protected boolean fHandleDefaultButton = true;
029:
030: class PartAdapter extends EditableTablePart {
031: private Label fCount;
032:
033: public PartAdapter(String[] buttonLabels) {
034: super (buttonLabels);
035: }
036:
037: public void entryModified(Object entry, String value) {
038: TableSection.this .entryModified(entry, value);
039: }
040:
041: public void selectionChanged(IStructuredSelection selection) {
042: getManagedForm().fireSelectionChanged(TableSection.this ,
043: selection);
044: TableSection.this .selectionChanged(selection);
045: }
046:
047: public void handleDoubleClick(IStructuredSelection selection) {
048: TableSection.this .handleDoubleClick(selection);
049: }
050:
051: public void buttonSelected(Button button, int index) {
052: TableSection.this .buttonSelected(index);
053: if (fHandleDefaultButton)
054: button.getShell().setDefaultButton(null);
055: }
056:
057: protected void createButtons(Composite parent,
058: FormToolkit toolkit) {
059: super .createButtons(parent, toolkit);
060: enableButtons();
061: if (createCount()) {
062: Composite comp = toolkit
063: .createComposite(fButtonContainer);
064: comp.setLayout(createButtonsLayout());
065: comp.setLayoutData(new GridData(
066: GridData.VERTICAL_ALIGN_END
067: | GridData.FILL_BOTH));
068: fCount = toolkit.createLabel(comp, ""); //$NON-NLS-1$
069: fCount.setForeground(toolkit.getColors().getColor(
070: IFormColors.TITLE));
071: fCount.setLayoutData(new GridData(
072: GridData.FILL_HORIZONTAL));
073: getTablePart().getTableViewer().getTable()
074: .addPaintListener(new PaintListener() {
075: public void paintControl(PaintEvent e) {
076: updateLabel();
077: }
078: });
079: }
080: }
081:
082: protected void updateLabel() {
083: if (fCount != null && !fCount.isDisposed())
084: fCount.setText(NLS.bind(
085: PDEUIMessages.TableSection_itemCount, Integer
086: .toString(getTableViewer().getTable()
087: .getItemCount())));
088: }
089: }
090:
091: /**
092: * Constructor for TableSection.
093: *
094: * @param formPage
095: */
096: public TableSection(PDEFormPage formPage, Composite parent,
097: int style, String[] buttonLabels) {
098: this (formPage, parent, style, true, buttonLabels);
099: }
100:
101: /**
102: * Constructor for TableSection.
103: *
104: * @param formPage
105: */
106: public TableSection(PDEFormPage formPage, Composite parent,
107: int style, boolean titleBar, String[] buttonLabels) {
108: super (formPage, parent, style, titleBar, buttonLabels);
109: }
110:
111: protected StructuredViewerPart createViewerPart(
112: String[] buttonLabels) {
113: return new PartAdapter(buttonLabels);
114: }
115:
116: protected IAction getRenameAction() {
117: return getTablePart().getRenameAction();
118: }
119:
120: protected EditableTablePart getTablePart() {
121: return (EditableTablePart) fViewerPart;
122: }
123:
124: protected void entryModified(Object entry, String value) {
125: }
126:
127: protected void selectionChanged(IStructuredSelection selection) {
128: }
129:
130: protected void handleDoubleClick(IStructuredSelection selection) {
131: }
132:
133: protected void enableButtons() {
134: }
135:
136: protected boolean createCount() {
137: return false;
138: }
139: }
|