001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.parts;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.jface.action.IAction;
014: import org.eclipse.jface.viewers.ICellModifier;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.jface.viewers.StructuredViewer;
017: import org.eclipse.jface.viewers.TableViewer;
018: import org.eclipse.jface.window.Window;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.pde.internal.ui.wizards.RenameDialog;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.ui.forms.widgets.FormToolkit;
023:
024: public class EditableTablePart extends TablePart {
025: private boolean editable;
026: private Action renameAction;
027:
028: class RenameAction extends Action {
029: public RenameAction() {
030: super (PDEUIMessages.EditableTablePart_renameAction);
031: }
032:
033: public void run() {
034: doRename();
035: }
036: }
037:
038: class NameModifier implements ICellModifier {
039: public boolean canModify(Object object, String property) {
040: return true;
041: }
042:
043: public void modify(Object object, String property, Object value) {
044: entryModified(object, value.toString());
045: }
046:
047: public Object getValue(Object object, String property) {
048: return object.toString();
049: }
050: }
051:
052: /**
053: * Constructor for EditableTablePart.
054: * @param buttonLabels
055: */
056: public EditableTablePart(String[] buttonLabels) {
057: super (buttonLabels);
058: }
059:
060: public boolean isEditable() {
061: return editable;
062: }
063:
064: public void setEditable(boolean editable) {
065: this .editable = editable;
066: }
067:
068: public IAction getRenameAction() {
069: if (renameAction == null)
070: renameAction = new RenameAction();
071: return renameAction;
072: }
073:
074: protected StructuredViewer createStructuredViewer(Composite parent,
075: int style, FormToolkit toolkit) {
076: TableViewer tableViewer = (TableViewer) super
077: .createStructuredViewer(parent, style, toolkit);
078: return tableViewer;
079: }
080:
081: private void doRename() {
082: TableViewer viewer = getTableViewer();
083: IStructuredSelection selection = (IStructuredSelection) viewer
084: .getSelection();
085: if (selection.size() == 1 && isEditable()) {
086: Object obj = selection.getFirstElement();
087: String oldName = obj.toString();
088: RenameDialog dialog = new RenameDialog(getControl()
089: .getShell(), oldName);
090: dialog.create();
091: dialog.getShell().setText(
092: PDEUIMessages.EditableTablePart_renameTitle);
093: dialog.getShell().setSize(300, 150);
094: if (dialog.open() == Window.OK) {
095: entryModified(obj, dialog.getNewName());
096: }
097: }
098: }
099:
100: protected void entryModified(Object entry, String value) {
101: }
102: }
|