KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > sdo > action > ApplyChangeAction


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: ApplyChangeAction.java,v 1.2 2005/06/08 06:21:18 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.sdo.action;
18
19
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.IActionDelegate;
24 import org.eclipse.ui.actions.ActionDelegate;
25
26 import org.eclipse.emf.common.command.AbstractCommand;
27 import org.eclipse.emf.ecore.sdo.EChangeSummary;
28 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
29 import org.eclipse.emf.edit.domain.EditingDomain;
30
31
32 /**
33  *
34  */

35 public class ApplyChangeAction
36   extends ActionDelegate
37   implements IActionDelegate
38 {
39   protected EChangeSummary changeSummary;
40
41   public ApplyChangeAction()
42   {
43   }
44
45   public void run(IAction action)
46   {
47     EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(changeSummary);
48     if (editingDomain != null)
49     {
50       editingDomain.getCommandStack().execute(
51         new
52           AbstractCommand()
53           {
54             protected boolean prepare() { return true; }
55             public boolean canUndo() { return false; }
56             public void execute() { changeSummary.apply(); }
57             public void redo() {}
58           });
59     }
60   }
61
62   public void selectionChanged(IAction action, ISelection selection)
63   {
64     if (selection instanceof IStructuredSelection)
65     {
66       Object JavaDoc object = ((IStructuredSelection)selection).getFirstElement();
67       if (object instanceof EChangeSummary)
68       {
69         changeSummary = (EChangeSummary)object;
70         if (!changeSummary.isLogging())
71         {
72           action.setEnabled(true);
73           return;
74         }
75       }
76     }
77     changeSummary = null;
78     action.setEnabled(false);
79   }
80
81 }
82
Popular Tags