Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9ec56e816e323832ecd77ec33dec726ca7a5fa86 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*****************************************************************************
 * Copyright (c) 2013 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:
 *  Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.nattable.common.helper;

import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.nattable.common.handlers.PolicyDefinedTableHandler;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable;
import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;


/**
 * Represents the prototype of a table defined in a viewpoint
 * @author Laurent Wouters
 */
public class TableViewPrototype extends ViewPrototype {
	private URI configFile;
	
	public TableViewPrototype(PapyrusTable configuration) {
		super(configuration);
		configFile = URI.createURI(configuration.getConfiguration());
	}
	
	public TableViewPrototype(PapyrusSyncTable configuration, String file) {
		super(configuration);
		configFile = URI.createURI(file);
	}
	
	@Override
	public boolean isOwnerReassignable() {
		return true;
	}
	
	@Override
	public boolean instantiateOn(EObject owner) {
		return instantiateOn(owner, null);
	}
	
	@Override
	public boolean instantiateOn(EObject owner, String name) {
		if (configFile == null)
			return false;
		PolicyDefinedTableHandler handler = new PolicyDefinedTableHandler(configFile, owner, name);
		return handler.execute(this);
	}

	@Override
	public Command getCommandChangeOwner(EObject view, final EObject target) {
		final Table table = (Table)view;
		final EObject previous = table.getOwner();
		return new AbstractCommand("Change table owner") {
			@Override
			public void execute() {
				table.setOwner(target);
			}
			@Override
			public void undo() {
				table.setOwner(previous);
			}
			@Override
			public void redo() {
				table.setOwner(target);
			}
			@Override
			protected boolean prepare() { return true; }
		};
	}

	@Override
	public Command getCommandChangeRoot(EObject view, final EObject target) {
		final Table table = (Table)view;
		final EObject previous = table.getContext();
		return new AbstractCommand("Change table root element") {
			@Override
			public void execute() {
				table.setContext(target);
			}
			@Override
			public void undo() {
				table.setContext(previous);
			}
			@Override
			public void redo() {
				table.setContext(target);
			}
			@Override
			protected boolean prepare() { return true; }
		};
	}

	@Override
	public EObject getOwnerOf(EObject view) {
		return ((Table)view).getOwner();
	}

	@Override
	public EObject getRootOf(EObject view) {
		return ((Table)view).getContext();
	}
}

Back to the top