View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.command;
19  
20  import org.vectomatic.dom.svg.utils.SVGConstants;
21  import org.vectomatic.svg.edit.client.engine.SVGModel;
22  import org.vectomatic.svg.edit.client.model.ModelConstants;
23  import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
24  
25  import com.extjs.gxt.ui.client.data.BeanModel;
26  import com.extjs.gxt.ui.client.data.BeanModelLookup;
27  import com.extjs.gxt.ui.client.util.Format;
28  
29  /**
30   * Generic command class to record addition of new SVG elements
31   * to the model.
32   * @author laaglu
33   */
34  public class GenericAddCommand extends CommandBase {
35  	protected SVGElementModel model;
36  	protected SVGElementModel parentModel;
37  	protected String name;
38  	protected SVGModel owner;
39  
40  	public GenericAddCommand(CommandFactoryBase factory, SVGElementModel model) {
41  		super(factory);
42  		this.model = model;
43  		owner = model.getOwner();
44  		parentModel = (SVGElementModel)model.getParent();
45  		name = model.<String>get(SVGConstants.SVG_TITLE_TAG);
46  	}
47  
48  	@Override
49  	public String getDescription() {
50  		return Format.substitute(ModelConstants.INSTANCE.addCmd(), name);
51  	}
52  
53  	@Override
54  	public void commit() {
55  		owner.add(parentModel, model);
56  	}
57  
58  	@Override
59  	public void rollback() {
60  		owner.remove(model);
61  	}
62  
63  	@Override
64  	public BeanModel asModel() {
65  		return BeanModelLookup.get().getFactory(GenericAddCommand.class).createModel(this);
66  	}
67  }