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: EnhanceNodesCommand.java
13   * Created: 2008-11-27
14   * Author: tmilos
15   * $Id: EnhanceNodesCommand.java 3217 2009-08-19 12:00:08Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.command;
19  
20  
21  import java.lang.reflect.InvocationTargetException;
22  
23  import org.apache.log4j.Logger;
24  import org.eclipse.core.runtime.IProgressMonitor;
25  import org.eclipse.gef.commands.Command;
26  import org.eclipse.jface.operation.IRunnableWithProgress;
27  import org.eclipse.osgi.util.NLS;
28  
29  import pl.edu.agh.cast.Activator;
30  import pl.edu.agh.cast.CastApplication;
31  import pl.edu.agh.cast.backward.editor.EditorUtilBackward;
32  import pl.edu.agh.cast.model.base.IDataSet;
33  import pl.edu.agh.cast.model.visual.backward.IDiagram;
34  import pl.edu.agh.cast.ui.util.MsgBoxHelper;
35  import pl.edu.agh.cast.util.IExceptionHandler;
36  import pl.edu.agh.cast.util.Messages;
37  
38  /**
39   * A command that is to enhance {@link pl.edu.agh.cast.model.visual.backward.Node}s from a {@link IDiagram} with
40   * attributes from matching entities of given {@link IDataSet}.
41   *
42   * This operation is not <em>UnDo</em>-able!
43   *
44   * For details see
45   *
46   * @see IDiagram#addAttributesFromEntities(java.util.Collection, java.util.Collection, java.util.Map, String, String,
47   *      String, org.eclipse.core.runtime.IProgressMonitor)
48   *
49   * @author AGH CAST Team
50   */
51  public class EnhanceNodesCommand extends Command {
52  
53  	private static Logger log = Activator.getLogger();
54  
55  	private IDiagram diagram;
56  
57  	private IDataSet dataSet;
58  
59  	/**
60  	 * Command constructor.
61  	 *
62  	 * @param diagram
63  	 *            the diagram to enhance
64  	 * @param dataSet
65  	 *            enhancing data set
66  	 */
67  	public EnhanceNodesCommand(IDiagram diagram, IDataSet dataSet) {
68  		this.diagram = diagram;
69  		this.dataSet = dataSet;
70  	}
71  
72  	/**
73  	 * This method always returns <code>false</code>.
74  	 *
75  	 * {@inheritDoc}
76  	 *
77  	 * @see org.eclipse.gef.commands.Command#canUndo()
78  	 */
79  	@Override
80  	public boolean canUndo() {
81  		return false;
82  	}
83  
84  	/**
85  	 * {@inheritDoc}
86  	 *
87  	 * @see org.eclipse.gef.commands.Command#execute()
88  	 */
89  	@Override
90  	public void execute() {
91  		EditorUtilBackward.runWithProgressMonitorInUIThread(new IRunnableWithProgress() {
92  			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
93  				diagram.addAttributesFromEntities(dataSet.getEntities(), null, null, null, monitor);
94  			}
95  		}, new IExceptionHandler() {
96  			public void handleException(Exception e) {
97  				String message = NLS.bind(Messages.EnhanceNodesCommand_0, dataSet.getId(), diagram.getDisplayName());
98  				MsgBoxHelper.showErrorBox(CastApplication.getActiveShell(), Messages.OperationError, message);
99  				log.error(message, e);
100 			}
101 		});
102 	}
103 
104 	/**
105 	 * {@inheritDoc}
106 	 *
107 	 * @see org.eclipse.gef.commands.Command#undo()
108 	 */
109 	@Override
110 	public void undo() {
111 		// do nothing
112 	}
113 
114 }