Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3b90bb4955c428c7332d36dabf4ffb69a6fe5cf5 (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
77
78
79
80
81
/**
 * Copyright (c) 2005-2006 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 */
package org.eclipse.emf.examples.extlibrary.actions;


import java.util.Collection;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.edit.command.CommandActionDelegate;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.IItemLabelProvider;


/**
 * The extended library example supports multi-rooted resources
 * and therefore this command will remove a library from the resource..
 */
public class RemoveLibraryCommand extends RemoveCommand implements CommandActionDelegate
{

  /* Attribute for the adapter factory */
  private IItemLabelProvider labelProvider = null;

  /**
   * Constructor
   * 
   * @param domain
   *            the editing domain
   * @param list
   *            the list to modify
   * @param collection
   *            the objects to be removed
   */
  public RemoveLibraryCommand(EditingDomain domain, EList<?> list, Collection<?> collection)
  {
    super(domain, list, collection);
    if (domain instanceof AdapterFactoryEditingDomain)
    {
      labelProvider = (IItemLabelProvider)((AdapterFactoryEditingDomain)domain).getAdapterFactory().adapt(
        collection.toArray()[0],
        IItemLabelProvider.class);
    }

    setLabel(LABEL);
    setDescription(DESCRIPTION);
  }

  /*
   * @see org.eclipse.emf.edit.command.CommandActionDelegate#getImage()
   */
  public Object getImage()
  {
    return this.labelProvider != null ? this.labelProvider.getImage(getCollection().toArray()[0]) : null;
  }

  /*
   * @see org.eclipse.emf.edit.command.CommandActionDelegate#getText()
   */
  public String getText()
  {
    return this.labelProvider != null ? this.labelProvider.getText(getCollection().toArray()[0]) : null;
  }

  /*
   * @see org.eclipse.emf.edit.command.CommandActionDelegate#getToolTipText()
   */
  public String getToolTipText()
  {
    return getText();
  }
}

Back to the top