package org.dbflute.erflute.editor.view.action.outline;

import java.util.List;

import org.dbflute.erflute.editor.model.ERDiagram;
import org.dbflute.erflute.editor.model.diagram_contents.element.node.ermodel.ERVirtualDiagram;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.PlatformUI;

/**
 * @author who?
 * @author kajiku
 */
public class ChangeNameAction extends AbstractOutlineBaseAction {

    public static final String ID = ChangeNameAction.class.getName();

    public ChangeNameAction(TreeViewer treeViewer) {
        super(ID, "Rename", treeViewer);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void execute(Event event) {

        final ERDiagram diagram = this.getDiagram();

        final List selectedEditParts = this.getTreeViewer().getSelectedEditParts();
        final EditPart editPart = (EditPart) selectedEditParts.get(0);
        final Object model = editPart.getModel();
        if (model instanceof ERVirtualDiagram) {
            final ERVirtualDiagram ermodel = (ERVirtualDiagram) model;

            final InputDialog dialog =
                    new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "���O�ύX",
                            "�_�C�A�O����������͂��ĉ������B", ermodel.getName(), null);
            if (dialog.open() == IDialogConstants.OK_ID) {
                ermodel.setName(dialog.getValue());
                diagram.getDiagramContents().getVirtualDiagramSet().changeModel(ermodel);
                ermodel.getDiagram().getEditor().setDirty(true);
                //				ermodel.changeAll();
                //				AddERModelCommand command = new AddERModelCommand(diagram, dialog.getValue());
                //				this.execute(command);
            }
        }

    }

}

@@ -1365,15 +1365,32 @@
 ), %22
-%EF%BF%BD%EF%BF%BD%EF%BF%BDO%EF%BF%BD%CF%8DX
+Rename%22, %22Input new name
 %22,%0A 
@@ -1419,41 +1419,8 @@
     
- %22%EF%BF%BD_%EF%BF%BDC%EF%BF%BDA%EF%BF%BDO%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%CD%82%EF%BF%BD%EF%BF%BD%C4%89%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDB%22,
  erm

fix changename diagram text