1 11 package org.eclipse.pde.internal.ui.editor; 12 import org.eclipse.jface.action.IAction; 13 import org.eclipse.jface.viewers.IStructuredSelection; 14 import org.eclipse.osgi.util.NLS; 15 import org.eclipse.pde.internal.ui.PDEUIMessages; 16 import org.eclipse.pde.internal.ui.parts.EditableTablePart; 17 import org.eclipse.pde.internal.ui.parts.StructuredViewerPart; 18 import org.eclipse.swt.events.PaintEvent; 19 import org.eclipse.swt.events.PaintListener; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.ui.forms.IFormColors; 25 import org.eclipse.ui.forms.widgets.FormToolkit; 26 27 public abstract class TableSection extends StructuredViewerSection { 28 protected boolean fHandleDefaultButton = true; 29 class PartAdapter extends EditableTablePart { 30 private Label fCount; 31 public PartAdapter(String [] buttonLabels) { 32 super(buttonLabels); 33 } 34 public void entryModified(Object entry, String value) { 35 TableSection.this.entryModified(entry, value); 36 } 37 public void selectionChanged(IStructuredSelection selection) { 38 getManagedForm().fireSelectionChanged(TableSection.this, selection); 39 TableSection.this.selectionChanged(selection); 40 } 41 public void handleDoubleClick(IStructuredSelection selection) { 42 TableSection.this.handleDoubleClick(selection); 43 } 44 public void buttonSelected(Button button, int index) { 45 TableSection.this.buttonSelected(index); 46 if (fHandleDefaultButton) 47 button.getShell().setDefaultButton(null); 48 } 49 protected void createButtons(Composite parent, FormToolkit toolkit) { 50 super.createButtons(parent, toolkit); 51 enableButtons(); 52 if (createCount()) { 53 Composite comp = toolkit.createComposite(fButtonContainer); 54 comp.setLayout(createButtonsLayout()); 55 comp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_BOTH)); 56 fCount = toolkit.createLabel(comp, ""); fCount.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); 58 fCount.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 59 getTablePart().getTableViewer().getTable().addPaintListener(new PaintListener() { 60 public void paintControl(PaintEvent e) { 61 updateLabel(); 62 } 63 }); 64 } 65 } 66 protected void updateLabel() { 67 if (fCount != null && !fCount.isDisposed()) 68 fCount.setText(NLS.bind( 69 PDEUIMessages.TableSection_itemCount, 70 Integer.toString(getTableViewer().getTable().getItemCount()))); 71 } 72 } 73 78 public TableSection(PDEFormPage formPage, Composite parent, int style, 79 String [] buttonLabels) { 80 this (formPage, parent, style, true, buttonLabels); 81 } 82 87 public TableSection(PDEFormPage formPage, Composite parent, int style, 88 boolean titleBar, String [] buttonLabels) { 89 super(formPage, parent, style, titleBar, buttonLabels); 90 } 91 protected StructuredViewerPart createViewerPart(String [] buttonLabels) { 92 return new PartAdapter(buttonLabels); 93 } 94 protected IAction getRenameAction() { 95 return getTablePart().getRenameAction(); 96 } 97 protected EditableTablePart getTablePart() { 98 return (EditableTablePart) fViewerPart; 99 } 100 protected void entryModified(Object entry, String value) { 101 } 102 protected void selectionChanged(IStructuredSelection selection) { 103 } 104 protected void handleDoubleClick(IStructuredSelection selection) { 105 } 106 protected void enableButtons() { 107 } 108 protected boolean createCount() { return false; } 109 } 110 | Popular Tags |