Commit a1ae5307 authored by Florian Hölzl's avatar Florian Hölzl

Kernel: JavaFX editor. Update to latest layout-based classes.

Issue-Ref: 3815
Issue-Url: https://af3-developer.fortiss.org/issues/3815Signed-off-by: Florian Hölzl's avatarFlorian Hoelzl <hoelzl@fortiss.org>
parent d1320bd0
......@@ -7,7 +7,7 @@ EReferencePropertySectionBase.java 0548da6778516003257f59d0b4c2b60d458be3b6 GREE
EditorBase.java 9c09fff92945256bb8680992ae7bb2c78f47b150 GREEN
FXEditorBase.java 2e520be0bbae7d0aebdff70218a124dbe0896ce2 YELLOW
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java 9d735ea8539b3bb829fcae258b506bd4e1a04e4e YELLOW
LWFXEFEditorBase.java ab11a24ea8d5ef9fe6d37eca2e11092c40791dc5 YELLOW
ModelEditorBindingBase.java 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN
ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
......
......@@ -15,12 +15,24 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.extension.base;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerSelection;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.change.Change;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IControllerFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelFactory;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IVisualFactory;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import javafx.scene.Parent;
......@@ -29,20 +41,24 @@ import javafx.scene.Parent;
*
* @author hoelzlf
*/
public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T> {
public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T>
implements ISelectionProvider {
/** The diagram viewer. */
protected DiagramViewer viewer;
/** The list of {@link ISelectionChangedListener}s. */
private final List<ISelectionChangedListener> selectionListeners = new ArrayList<>();
/** {@inheritDoc} */
@Override
protected final Parent createSceneRoot() {
viewer = new DiagramViewer(createModelFactory(), createVisualFactory(),
createControllerFactory(), cb -> {
modelSelected(cb);
modelSelected();
}, chg -> {
applyModelChange(chg);
});
customizeViewer();
getSite().setSelectionProvider(this);
return viewer.getVisualNode();
}
......@@ -61,8 +77,57 @@ public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T
protected abstract IControllerFactory createControllerFactory();
/** Called when a model element is selected in the diagram viewer. */
protected abstract void modelSelected(Object model);
protected void modelSelected() {
getSite().getSelectionProvider().setSelection(createSelection());
}
/** Called when some change to the model happens. */
protected abstract void applyModelChange(Change chg);
protected void applyModelChange(Change chg) {
ICommandStackService.getInstance().runAsCommand(editedObject, () -> {
chg.applyChange();
});
}
/** {@inheritDoc} */
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
if(!selectionListeners.contains(listener)) {
selectionListeners.add(listener);
}
}
/** {@inheritDoc} */
@Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
selectionListeners.remove(listener);
}
/** {@inheritDoc} */
@Override
public void setSelection(ISelection selection) {
SelectionChangedEvent evt = new SelectionChangedEvent(this, selection);
for(ISelectionChangedListener scl : selectionListeners) {
scl.selectionChanged(evt);
}
}
/** {@inheritDoc} */
@Override
public ISelection getSelection() {
return createSelection();
}
/** Creates an {@link IStructuredSelection} from {@link DiagramViewerSelection}. */
private IStructuredSelection createSelection() {
DiagramViewerSelection vsel = viewer.getSelection();
if(vsel.isEmpty()) {
return StructuredSelection.EMPTY;
}
List<Object> selList = new ArrayList<>(vsel.getSecondarySelections().size() + 1);
selList.add(vsel.getPrimarySelection().getModel());
for(IMVCBundle sec : vsel.getSecondarySelections()) {
selList.add(sec.getModel());
}
return new StructuredSelection(selList);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment