-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft for update infra of plant hier
- Loading branch information
1 parent
e6ada25
commit f64ae37
Showing
16 changed files
with
576 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
.../org/eclipse/fordiac/ide/hierarchymanager/ui/listeners/HierachyManagerUpdateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Primetals Technology Austria GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Michael Oberlehner - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.fordiac.ide.hierarchymanager.ui.listeners; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.core.commands.operations.AbstractOperation; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
import org.eclipse.emf.ecore.xmi.XMLResource; | ||
import org.eclipse.emf.ecore.xmi.impl.XMLMapImpl; | ||
import org.eclipse.fordiac.ide.hierarchymanager.model.hierarchy.HierarchyPackage; | ||
import org.eclipse.fordiac.ide.hierarchymanager.model.hierarchy.Leaf; | ||
import org.eclipse.fordiac.ide.hierarchymanager.model.hierarchy.RootLevel; | ||
import org.eclipse.fordiac.ide.hierarchymanager.model.hierarchy.util.HierarchyResourceFactoryImpl; | ||
import org.eclipse.fordiac.ide.hierarchymanager.ui.handlers.AbstractHierarchyHandler; | ||
import org.eclipse.fordiac.ide.hierarchymanager.ui.operations.AbstractChangeHierarchyOperation; | ||
import org.eclipse.fordiac.ide.hierarchymanager.ui.operations.UpdateLeafRefOperation; | ||
import org.eclipse.fordiac.ide.hierarchymanager.ui.util.HierarchyManagerUtil; | ||
import org.eclipse.fordiac.ide.hierarchymanager.ui.view.PlantHierarchyView; | ||
import org.eclipse.fordiac.ide.model.commands.CommandListener; | ||
import org.eclipse.fordiac.ide.model.commands.QualNameChange; | ||
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; | ||
import org.eclipse.fordiac.ide.model.libraryElement.UntypedSubApp; | ||
import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; | ||
import org.eclipse.ui.IWorkbenchPage; | ||
import org.eclipse.ui.PlatformUI; | ||
|
||
public class HierachyManagerUpdateListener extends CommandListener { | ||
|
||
private static EObject loadPlantHierachy(final IProject project) { | ||
final Map<String, Object> loadOptions = new HashMap<>(); | ||
final ResourceSet hierarchyResouceSet = new ResourceSetImpl(); | ||
hierarchyResouceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() | ||
.put(PlantHierarchyView.PLANT_HIERARCHY_FILE_NAME_EXTENSION, new HierarchyResourceFactoryImpl()); | ||
loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); | ||
final XMLMapImpl map = new XMLMapImpl(); | ||
map.setNoNamespacePackage(HierarchyPackage.eINSTANCE); | ||
loadOptions.put(XMLResource.OPTION_XML_MAP, map); | ||
hierarchyResouceSet.getLoadOptions().put(XMLResource.OPTION_XML_MAP, map); | ||
return PlantHierarchyView.loadHierachyForProject(project, hierarchyResouceSet, loadOptions); | ||
} | ||
|
||
private List<AbstractOperation> getOperationForCommand(final QualNameChange qualNameChange, | ||
final RootLevel rootLevel) { | ||
|
||
final String identifier = qualNameChange.oldQualName(); | ||
|
||
final List<AbstractOperation> result = new ArrayList<>(); | ||
|
||
if (undoSet.contains(qualNameChange)) { | ||
final List<AbstractOperation> l = executedOperations.get(qualNameChange); | ||
// TODO implement UNDO functionality | ||
} | ||
|
||
final List<Leaf> leafs = HierarchyManagerUtil.searchLeaf(rootLevel, leafRef -> leafRef.contains(identifier)); | ||
if (leafs == null || leafs.isEmpty()) { | ||
return null; // leaf may have been deleted in the meantime | ||
} | ||
|
||
final String newRef = qualNameChange.newQualName(); | ||
|
||
for (final Leaf leaf : leafs) { | ||
result.add(new UpdateLeafRefOperation(leaf, newRef)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public void commitOperations(final Object notifier) { | ||
|
||
if (!(notifier instanceof final TypeEntry key)) { | ||
return; | ||
} | ||
|
||
final List<QualNameChange> list = pendingChanges.get(key); | ||
if (list == null || list.isEmpty()) { | ||
// we only want to reload if changes have been performed | ||
return; | ||
} | ||
|
||
final RootLevel rootLevel = getPlantHierachy(key); | ||
|
||
for (final QualNameChange change : list) { | ||
final List<AbstractOperation> operation = getOperationForCommand(change, rootLevel); | ||
if (operation == null || operation.isEmpty()) { | ||
continue; | ||
// the leaf from the plant hierachy might have change in the meantime | ||
// TODO add to Plant hier a warning that we have umcomited change -> save all | ||
// editors before editing plant hierachy | ||
} | ||
|
||
operation.stream().forEach(op -> { | ||
AbstractHierarchyHandler.executeOperation((AbstractChangeHierarchyOperation) op); | ||
}); | ||
executedOperations.put(change, operation); | ||
} | ||
|
||
pendingChanges.remove(key); | ||
} | ||
|
||
private static RootLevel getPlantHierachy(final TypeEntry key) { | ||
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
if (page != null) { | ||
final PlantHierarchyView view = (PlantHierarchyView) page | ||
.findView("org.eclipse.fordiac.ide.hierarchymanager.view"); //$NON-NLS-1$ | ||
if (view != null) { | ||
return (RootLevel) view.getCommonViewer().getInput(); | ||
} | ||
} | ||
final IProject project = key.getFile().getProject(); | ||
return (RootLevel) loadPlantHierachy(project); | ||
} | ||
|
||
@Override | ||
protected boolean isEnabled(final INamedElement element) { | ||
return element instanceof UntypedSubApp; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...ui/src/org/eclipse/fordiac/ide/hierarchymanager/ui/operations/UpdateLeafRefOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Primetals Technology Austria GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Michael Oberlehner - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.fordiac.ide.hierarchymanager.ui.operations; | ||
|
||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.runtime.IAdaptable; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.fordiac.ide.hierarchymanager.model.hierarchy.Leaf; | ||
|
||
public class UpdateLeafRefOperation extends AbstractChangeHierarchyOperation { | ||
|
||
private final Leaf leaf; | ||
private final String newRef; | ||
private final String oldRef; | ||
|
||
public UpdateLeafRefOperation(final Leaf level, final String newRef) { | ||
super("Update Reference"); | ||
this.leaf = level; | ||
this.newRef = newRef; | ||
this.oldRef = leaf.getRef(); | ||
} | ||
|
||
@Override | ||
public IStatus execute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { | ||
leaf.setRef(leaf.getRef().replace(oldRef, newRef)); | ||
saveHierarchy(leaf, monitor); | ||
return Status.OK_STATUS; | ||
} | ||
|
||
@Override | ||
public IStatus redo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { | ||
leaf.setRef(leaf.getRef().replace(oldRef, newRef)); | ||
saveHierarchy(leaf, monitor); | ||
return Status.OK_STATUS; | ||
} | ||
|
||
@Override | ||
public IStatus undo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { | ||
leaf.setRef(leaf.getRef().replace(newRef, oldRef)); | ||
saveHierarchy(leaf, monitor); | ||
return Status.OK_STATUS; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.2"?> | ||
<plugin> | ||
<extension-point | ||
id="CommandListener" | ||
name="Command Listener" | ||
schema="schema/CommandListener.exsd"> | ||
</extension-point> | ||
</plugin> |
25 changes: 25 additions & 0 deletions
25
plugins/org.eclipse.fordiac.ide.model.commands/schema/CommandListener.exsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="org.eclipse.fordiac.ide.model.commands" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appinfo> | ||
<meta.schema plugin="org.eclipse.fordiac.ide.model.commands" id="org.eclipse.fordiac.ide.model.commands.CommandListener" name="Extension point for listening on commands"/> | ||
</appinfo> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
|
||
<element name="listener"> | ||
<complexType> | ||
<attribute name="class" type="java:org.eclipse.core.runtime.IExecutableExtension" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
</schema> |
Oops, something went wrong.