Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fbfabda458f25170c3efd53011b791052b5f85e2 (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
/***************************************************************************
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
 * 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:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.net4j.util.internal.ui.views;

import org.eclipse.net4j.util.internal.ui.SharedIcons;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.ui.actions.SafeAction;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
import org.eclipse.net4j.util.ui.views.ContainerView;
import org.eclipse.net4j.util.ui.views.IElementFilter;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.swt.graphics.Image;

import java.util.Iterator;

/**
 * @author Eike Stepper
 */
public class Net4jItemProvider extends ContainerItemProvider
{
  public Net4jItemProvider()
  {
  }

  public Net4jItemProvider(IElementFilter rootElementFilter)
  {
    super(rootElementFilter);
  }

  @Override
  protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
  {
    manager.add(new RemoveAction(selection));
  }

  @Override
  public Image getImage(Object obj)
  {
    return SharedIcons.getImage(SharedIcons.OBJ_BEAN);
  }

  /**
   * @author Eike Stepper
   */
  public class RemoveAction extends SafeAction
  {
    private ITreeSelection selection;

    public RemoveAction(ITreeSelection selection)
    {
      super("Remove", "Remove", ContainerView.getDeleteImageDescriptor());
      this.selection = selection;
    }

    @Override
    protected void doRun() throws Exception
    {
      for (Iterator it = selection.iterator(); it.hasNext();)
      {
        Object object = it.next();
        LifecycleUtil.deactivate(object);
      }
    }
  }
}

Back to the top