Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: ff54dbe1b465d49a3da8ab589a79689b3534c54c (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
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * 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:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.internal.common;



import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;

/**
 * This is a specialized editing domain that can be used by editors that have one or more design
 * pages that view a MOF model and a source page that contains an XML Model.
 */
public class StructuredTextEditingDomain extends AdapterFactoryEditingDomain implements IStructuredTextEditingDomain {
	protected IStructuredTextUndoManager undoManager;

	/**
	 * StructuredTextEditingDomain constructor comment.
	 * 
	 * @param adapterFactory
	 *            org.eclipse.emf.common.notify.AdapterFactory
	 * @param commandStack
	 *            CommandStack
	 */
	public StructuredTextEditingDomain(AdapterFactory adapterFactory, CommandStack commandStack) {
		super(adapterFactory, commandStack);
	}

	public StructuredTextEditingDomain(AdapterFactory adapterFactory, CommandStack commandStack, ResourceSet resourceSet) {
		super(adapterFactory, commandStack, resourceSet);
	}

	/**
	 * Execute a command within the editing domain.
	 */
	public void execute(Command command) {
		execute(command.getLabel(), command);
	}

	/**
	 * Execute a command within the editing domain.
	 */
	public void execute(String label, Command command) {
		executeViaUndoManager(label, command);
	}

	/**
	 * Execute a command directly on the command stack
	 */
	public void executeViaStack(Command command) {
		getCommandStack().execute(command);
	}

	/**
	 * Execute a command within the editing domain.
	 */
	public void executeViaUndoManager(String label, Command command) {
		if (command.canExecute()) {
			if (undoManager != null) {
				undoManager.beginRecording(this, label);
				command.execute();
				undoManager.endRecording(this);
			} else
				executeViaStack(command);
		}
	}

	public IStructuredTextUndoManager getUndoManager() {
		return undoManager;
	}

	public void setUndoManager(IStructuredTextUndoManager newUndoManager) {
		undoManager = newUndoManager;
		undoManager.setCommandStack(commandStack);
	}
}

Back to the top