129 lines
2.7 KiB
Java
Executable File
129 lines
2.7 KiB
Java
Executable File
package pyUML.pythonTree;
|
|
|
|
import org.eclipse.core.resources.IProject;
|
|
import org.eclipse.uml2.uml.NamedElement;
|
|
|
|
import pyUML.exceptions.PyUMLCancelledException;
|
|
import pyUML.exceptions.PyUMLSynchronizeCodeException;
|
|
|
|
|
|
|
|
/**
|
|
* A generic node of the Python package structure tree
|
|
* This class is used as abstract super class for all
|
|
* PythonTree Elements
|
|
*/
|
|
|
|
public abstract class PythonTreeNode {
|
|
private PythonTreeNode parent;
|
|
protected String name;
|
|
protected String xmi_id;
|
|
private NamedElement associatedModelElement;
|
|
|
|
|
|
public PythonTreeNode(PythonTreeNode parent) {
|
|
this.parent = parent;
|
|
}
|
|
|
|
/**
|
|
* returns the parent of this package.
|
|
* If this is the root, return null.
|
|
* @return
|
|
*/
|
|
public PythonTreeNode getParent() {
|
|
if (! this.isRoot())
|
|
return parent;
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Synchronize the model from the given model element
|
|
* downwards.
|
|
* Create, delete and move model elements
|
|
*
|
|
* @param modelElement
|
|
* @return
|
|
*/
|
|
public boolean synchronizeModel(NamedElement modelElement) {
|
|
this.associatedModelElement = modelElement;
|
|
|
|
// test if name changed -> update model element name if name changed
|
|
if (! this.isRoot() && (!this.getName().equals(modelElement.getName()))) {
|
|
modelElement.setName(this.getName());
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Opposite of synchronizeModel; Synchronizes the code
|
|
* with a given model
|
|
*
|
|
* @param umlElement
|
|
* @return true if code was changed (so that the python tree
|
|
* has to be updated), false if everything went OK
|
|
*/
|
|
public boolean synchronizeCode(NamedElement modelElement) throws PyUMLSynchronizeCodeException, PyUMLCancelledException{
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* after running synchronizeModel, this method returns the corresponding
|
|
* UML Model NamedElement of this PythonTreeNode
|
|
* @return
|
|
*/
|
|
public NamedElement getAssociatedModelElement() {
|
|
return associatedModelElement;
|
|
}
|
|
|
|
/**
|
|
* method to easily find out if this is the Root
|
|
* of the Python Package Tree
|
|
*
|
|
* @return false, if this is a package,
|
|
* the subclass PythonTreeRoot returns true
|
|
*/
|
|
public boolean isRoot() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Gets the XMI-id of this node,
|
|
* or null, if no XMI-ID was defined
|
|
* @return
|
|
*/
|
|
public String getXmi_id() {
|
|
return xmi_id;
|
|
}
|
|
|
|
/**
|
|
* @return the root Element of this PythonTree
|
|
*/
|
|
public PythonTreeRoot getRoot() {
|
|
if (this.isRoot())
|
|
return (PythonTreeRoot) this;
|
|
else
|
|
return this.getParent().getRoot();
|
|
}
|
|
|
|
/**
|
|
* Get the name of this node
|
|
* @return
|
|
*/
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Get the Eclipse project that was used while creating this node
|
|
* @return
|
|
*/
|
|
public IProject getProject() {
|
|
return this.getRoot().getProject();
|
|
}
|
|
|
|
}
|