use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class TreeModelViewerDragDropHandler method moveTreeObjects.
/**
* Move Tree Objects
*/
void moveTreeObjects(IFolder newParent, Object[] objects) {
final CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.TreeModelViewerDragDropHandler_0 : super.getLabel();
}
};
for (Object object : objects) {
if (object instanceof IFolder) {
// This first - folders go in folders
if (!newParent.getFolders().contains(object)) {
compoundCommand.add(new MoveFolderCommand(newParent, (IFolder) object));
}
} else if (object instanceof IArchimateModelObject) {
if (!newParent.getElements().contains(object)) {
compoundCommand.add(new MoveObjectCommand(newParent, (IArchimateModelObject) object));
}
}
}
CommandStack stack = (CommandStack) newParent.getAdapter(CommandStack.class);
stack.execute(compoundCommand);
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class AbstractModelView method getParentToRefreshFromNotification.
/**
* @return The parent node to refresh when one of its children is added/removed/set
*/
protected Object getParentToRefreshFromNotification(Notification msg) {
int type = msg.getEventType();
Object element = null;
if (type == Notification.REMOVE) {
element = msg.getNotifier();
} else if (type == Notification.ADD) {
element = msg.getNewValue();
if (element instanceof EObject) {
element = ((EObject) element).eContainer();
}
} else if (type == Notification.SET) {
// Name changed - need to refresh parent node because of using a ViewerSorter to sort on name
if (msg.getFeature() == IArchimatePackage.Literals.NAMEABLE__NAME) {
element = msg.getNotifier();
if (element instanceof EObject) {
element = ((EObject) element).eContainer();
}
}
}
return (element instanceof IFolder || element instanceof IArchimateModel) ? element : null;
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class DeleteCommandHandler method createCommands.
/**
* Create the Delete Commands
*/
private void createCommands() {
/*
* We need to ensure that the Delete Diagram Model Commands are called first in order to close
* any open diagram editors before removing their models from parent folders.
*/
for (Object object : fElementsToDelete) {
if (object instanceof IDiagramModel) {
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
if (compoundCommand != null) {
Command cmd = new DeleteDiagramModelCommand((IDiagramModel) object);
compoundCommand.add(cmd);
} else {
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in " + getClass());
}
}
}
/*
* Then the other types
*/
for (Object object : fElementsToDelete) {
if (object instanceof IDiagramModel) {
// already done
continue;
}
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
if (compoundCommand == null) {
// sanity check
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in " + getClass());
continue;
}
if (object instanceof IFolder) {
Command cmd = new DeleteFolderCommand((IFolder) object);
compoundCommand.add(cmd);
} else if (object instanceof IArchimateElement) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) object);
compoundCommand.add(cmd);
} else if (object instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) object);
compoundCommand.add(cmd);
} else if (object instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) object);
compoundCommand.add(cmd);
} else if (object instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) object);
compoundCommand.add(cmd);
}
}
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class NewFolderAction method run.
@Override
public void run() {
Object selected = getSelection().getFirstElement();
if (selected instanceof IFolder) {
IFolder parent = (IFolder) selected;
// Create a new Folder, set its name
IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
folder.setName(Messages.NewFolderAction_1);
folder.setType(FolderType.USER);
// Execute Command
Command cmd = new NewFolderCommand(parent, folder);
CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
}
use of com.archimatetool.model.IFolder in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelExporter method createAndSaveResourceForFolder.
/**
* For each folder inside model, create a directory and a Resource to save it.
* For each element, create a Resource to save it
*
* @param folderContainer Model or folder to work on
* @param folder Directory in which to generate files
* @throws IOException
*/
private void createAndSaveResourceForFolder(IFolderContainer folderContainer, File folder) throws IOException {
// Save each children folders
List<IFolder> allFolders = new ArrayList<IFolder>();
allFolders.addAll(folderContainer.getFolders());
for (IFolder tmpFolder : allFolders) {
File tmpFolderFile = new File(folder, getNameFor(tmpFolder));
tmpFolderFile.mkdirs();
createAndSaveResource(new File(tmpFolderFile, IGraficoConstants.FOLDER_XML), tmpFolder);
createAndSaveResourceForFolder(tmpFolder, tmpFolderFile);
}
// Save each children elements
if (folderContainer instanceof IFolder) {
// Save each children element
List<EObject> allElements = new ArrayList<EObject>();
allElements.addAll(((IFolder) folderContainer).getElements());
for (EObject tmpElement : allElements) {
createAndSaveResource(// $NON-NLS-1$ //$NON-NLS-2$
new File(folder, tmpElement.getClass().getSimpleName() + "_" + ((IIdentifier) tmpElement).getId() + ".xml"), tmpElement);
}
}
if (folderContainer instanceof IArchimateModel) {
createAndSaveResource(new File(folder, IGraficoConstants.FOLDER_XML), folderContainer);
}
}
Aggregations