| /* |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| * Loetz GmbH&Co.KG |
| * |
| */ |
| package org.eclipse.osbp.vaadin.emf.commands; |
| |
| import org.eclipse.emf.common.command.AbstractCommand; |
| import org.eclipse.emf.common.notify.Notifier; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.resource.Resource; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * Uses the {@link ChangeCommand} to record notifications. |
| */ |
| public abstract class ChangeCommand extends AbstractCommand { |
| |
| /** The notifier. */ |
| private Notifier notifier; |
| |
| /** The recorder. */ |
| private ChangedRecorder recorder; |
| |
| /** |
| * Instantiates a new change command. |
| * |
| * @param name |
| * the name |
| * @param resource |
| * the resource |
| */ |
| public ChangeCommand(String name, Resource resource) { |
| super(name); |
| this.notifier = resource; |
| |
| if (resource == null) { |
| throw new IllegalArgumentException("resource must not be null!"); |
| } |
| } |
| |
| /** |
| * Instantiates a new change command. |
| * |
| * @param name |
| * the name |
| * @param notifier |
| * the notifier |
| */ |
| public ChangeCommand(String name, EObject notifier) { |
| super(name); |
| this.notifier = notifier; |
| |
| if (notifier == null) { |
| throw new IllegalArgumentException("notifier must not be null!"); |
| } |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.Command#execute() |
| */ |
| @Override |
| public void execute() { |
| recorder.start(); |
| |
| doExecute(); |
| |
| recorder.stop(); |
| } |
| |
| /** |
| * Execute your operations. |
| */ |
| protected abstract void doExecute(); |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.Command#redo() |
| */ |
| @Override |
| public void redo() { |
| recorder.redo(); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.AbstractCommand#prepare() |
| */ |
| @Override |
| protected boolean prepare() { |
| recorder = new ChangedRecorder(notifier); |
| return true; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.AbstractCommand#undo() |
| */ |
| @Override |
| public void undo() { |
| recorder.undo(); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.AbstractCommand#canUndo() |
| */ |
| @Override |
| public boolean canUndo() { |
| return super.canUndo(); |
| } |
| |
| } |