1 11 package org.eclipse.pde.internal.ui.parts; 12 import org.eclipse.jface.action.Action; 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.viewers.ICellModifier; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.jface.viewers.StructuredViewer; 17 import org.eclipse.jface.viewers.TableViewer; 18 import org.eclipse.jface.window.Window; 19 import org.eclipse.pde.internal.ui.PDEUIMessages; 20 import org.eclipse.pde.internal.ui.wizards.RenameDialog; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.ui.forms.widgets.FormToolkit; 23 24 public class EditableTablePart extends TablePart { 25 private boolean editable; 26 private Action renameAction; 27 28 class RenameAction extends Action { 29 public RenameAction() { 30 super(PDEUIMessages.EditableTablePart_renameAction); 31 } 32 public void run() { 33 doRename(); 34 } 35 } 36 37 class NameModifier implements ICellModifier { 38 public boolean canModify(Object object, String property) { 39 return true; 40 } 41 public void modify(Object object, String property, Object value) { 42 entryModified(object, value.toString()); 43 } 44 public Object getValue(Object object, String property) { 45 return object.toString(); 46 } 47 } 48 52 public EditableTablePart(String [] buttonLabels) { 53 super(buttonLabels); 54 } 55 56 public boolean isEditable() { 57 return editable; 58 } 59 60 public void setEditable(boolean editable) { 61 this.editable = editable; 62 } 63 64 public IAction getRenameAction() { 65 if (renameAction==null) renameAction = new RenameAction(); 66 return renameAction; 67 } 68 69 protected StructuredViewer createStructuredViewer( 70 Composite parent, 71 int style, 72 FormToolkit toolkit) { 73 TableViewer tableViewer = 74 (TableViewer) super.createStructuredViewer(parent, style, toolkit); 75 return tableViewer; 76 } 77 78 private void doRename() { 79 TableViewer viewer = getTableViewer(); 80 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); 81 if (selection.size()==1 && isEditable()) { 82 Object obj = selection.getFirstElement(); 83 String oldName = obj.toString(); 84 RenameDialog dialog = new RenameDialog(getControl().getShell(), oldName); 85 dialog.create(); 86 dialog.getShell().setText(PDEUIMessages.EditableTablePart_renameTitle); 87 dialog.getShell().setSize(300, 150); 88 if (dialog.open() == Window.OK) { 89 entryModified(obj, dialog.getNewName()); 90 } 91 } 92 } 93 94 protected void entryModified(Object entry, String value) { 95 } 96 } 97 | Popular Tags |