Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2931cadf468c0504c425f3d6575e58dd5f7ac581 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Victor Roldan Betancort - initial API and implementation
 *    Eike Stepper - maintenance
 */
package org.eclipse.emf.cdo.ui.internal.ide.actions;

import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.internal.ui.actions.ResourceNodeNameInputValidator;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.ui.internal.ide.messages.Messages;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;

/**
 * @author Victor Roldan Betancort
 */
public class RenameResourceNodeActionDelegate extends TransactionalBackgroundActionDelegate
{
  private String newResourceName;

  public RenameResourceNodeActionDelegate()
  {
    super(Messages.getString("RenameResourceNodeActionDelegate.0")); //$NON-NLS-1$
  }

  @Override
  protected CDOObject preRun(CDOObject object)
  {
    InputDialog dialog = new InputDialog(getTargetPart().getSite().getShell(), getText(), Messages
        .getString("NewResourceNodeAction_0"), null, new ResourceNodeNameInputValidator((CDOResourceNode)object)); //$NON-NLS-1$
    if (dialog.open() == Dialog.OK)
    {
      setNewResourceName(dialog.getValue());
      return super.preRun(object);
    }

    cancel();

    return null;
  }

  private void setNewResourceName(String newName)
  {
    newResourceName = newName;
  }

  private String getNewResourceName()
  {
    return newResourceName;
  }

  @Override
  protected final void doRun(CDOTransaction transaction, CDOObject object, IProgressMonitor progressMonitor)
      throws Exception
  {
    if (object instanceof CDOResourceNode)
    {
      ((CDOResourceNode)object).setName(getNewResourceName());
    }
    else
    {
      throw new IllegalArgumentException("object is not a CDOResourceNode"); //$NON-NLS-1$
    }
  }

}

Back to the top