View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: RemoveMetaPropertiesCommand.java
13   * Created: 2009-08-12
14   * Author: kpietak
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast.command;
19  
20  import java.util.Collection;
21  
22  import org.eclipse.gef.commands.Command;
23  
24  import pl.edu.agh.cast.data.model.property.IPropertyContainer;
25  import pl.edu.agh.cast.data.model.property.MetaProperty;
26  
27  /**
28   * Removes permanently given meta property and all associated properties. This command cannot be undone.
29   *
30   * @author AGH CAST Team
31   */
32  public class RemoveMetaPropertiesCommand extends Command {
33  
34  	private IPropertyContainer container;
35  
36  	private Collection<MetaProperty> metaProperties;
37  
38  	/**
39  	 * Constructor.
40  	 *
41  	 * @param container
42  	 * @param metaProperties
43  	 */
44  	public RemoveMetaPropertiesCommand(IPropertyContainer container, Collection<MetaProperty> metaProperties) {
45  		if (container == null || metaProperties == null || metaProperties.isEmpty()) {
46  			throw new IllegalArgumentException();
47  		}
48  		this.container = container;
49  		this.metaProperties = metaProperties;
50  	}
51  
52  	/**
53  	 * Always returns false as the commend cannot be undone. {@inheritDoc}
54  	 *
55  	 * @see org.eclipse.gef.commands.Command#canUndo()
56  	 */
57  	@Override
58  	public boolean canUndo() {
59  		return false;
60  	}
61  
62  	/**
63  	 * {@inheritDoc}
64  	 *
65  	 * @see org.eclipse.gef.commands.Command#execute()
66  	 */
67  	@Override
68  	public void execute() {
69  		for (MetaProperty metaProperty : metaProperties) {
70  			container.getMetaPropertyManager().removeMetaProperty(metaProperty.getName());
71  		}
72  	}
73  
74  }