KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 JavaDoc object, String JavaDoc property) {
39             return true;
40         }
41         public void modify(Object JavaDoc object, String JavaDoc property, Object JavaDoc value) {
42             entryModified(object, value.toString());
43         }
44         public Object JavaDoc getValue(Object JavaDoc object, String JavaDoc property) {
45             return object.toString();
46         }
47     }
48     /**
49      * Constructor for EditableTablePart.
50      * @param buttonLabels
51      */

52     public EditableTablePart(String JavaDoc[] 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 JavaDoc obj = selection.getFirstElement();
83             String JavaDoc 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 JavaDoc entry, String JavaDoc value) {
95     }
96 }
97
Popular Tags