blob: df786b474cf052bd2f6d1e63121e040dfbfcbc49 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*****************************************************************************
* Copyright (c) 2011 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.table.modelexplorer.handlers;
import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.nattable.instance.papyrustableinstance.PapyrusTableInstance;
import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
import org.eclipse.papyrus.table.modelexplorer.messages.Messages;
/**
* This handler provides the duplicate action for the tables
*
*
*
*/
public class DuplicateTableHandler extends AbstractTableModelExplorerHandler {
/**
*
* @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
*
* @return
*/
@Override
protected Command getCommand() {
TransactionalEditingDomain editingDomain = getEditingDomain();
final IPageMngr pageManager = getPageManager();
List<PapyrusTableInstance> tables = getSelectedTables();
if(editingDomain != null && pageManager != null && !tables.isEmpty()) {
CompoundCommand command = new CompoundCommand();
for(PapyrusTableInstance table : tables) {
// Clone the current table
final PapyrusTableInstance newTable = EcoreUtil.copy(table);
// Give a new name
newTable.setName(Messages.DuplicateTableHandler_CopyOf + newTable.getName());
//we duplicate parameters and rename the new table!
Command addGmfDiagramCmd = new AddCommand(editingDomain, table.eResource().getContents(), newTable);
// EMFCommandOperation operation = new EMFCommandOperation(editingDomain, addGmfDiagramCmd);
Command sashOpenCmd = new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
pageManager.openPage(newTable);
}
};
//
// // TODO : synchronize with Cedric
// command.append(operation.getCommand());
command.append(addGmfDiagramCmd);
command.append(sashOpenCmd);
}
return command.isEmpty() ? UnexecutableCommand.INSTANCE : command;
}
return UnexecutableCommand.INSTANCE;
}
}
|