Skip to content
Snippets Groups Projects
Commit deb23e9d authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Kernel: JavaFX editor. Moved utility class and fixed lambdas.

parent 90b61a63
No related branches found
No related tags found
1 merge request!743815 LWFXEditorFramework integration and FX Component Editor
......@@ -5,6 +5,7 @@ DragAndDropBaseUtils.java d375377f9124f6113b2a295e6b0e09ac8966e564 GREEN
EllipseLayoutUIUtils.java 4dd9dbd96a45e8c455c019caa19e4a50f18336af GREEN
FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN
GCStateManager.java 983973a92376b5c757c1253b32e33d0666ccdf7b GREEN
LWFXEditorUtils.java af4bb6efdc13e52996f6e23b95217e8b5947b478 YELLOW
LayoutDataUIUtils.java c85886ac313a6efb122532218eb134047ffd6631 GREEN
PropertiesViewUtils.java d345b4501c4092228edf1c98e0189317d53aaf22 GREEN
RectangleLayoutUIUtils.java ef4b872bb5b4a51174e9a29d9ef05e7cb3bff3a1 GREEN
......
/*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.fortiss.tooling.base.model.layout.EOrientation;
import javafx.geometry.Rectangle2D;
import javafx.geometry.Side;
/**
* Utility methods for the JavaFX-based graphical LWFXEF editors.
*
* @author hoelzl
*/
public final class LWFXEditorUtils {
/** Computes the location of the link w.r.t. the given anchor bounds and target position. */
public static DiagramCoordinate computeLinkToAnchorLocation(Rectangle2D anchorBounds,
DiagramCoordinate target) {
double x = 0;
if(target.getX() < anchorBounds.getMinX()) {
x = -1.0;
} else if(target.getX() > anchorBounds.getMaxX()) {
x = 1.0;
}
double y = 0;
if(target.getY() < anchorBounds.getMinY()) {
y = -1.0;
} else if(target.getY() > anchorBounds.getMaxY()) {
y = 1.0;
}
double w2 = anchorBounds.getWidth() / 2;
double h2 = anchorBounds.getHeight() / 2;
x = anchorBounds.getMinX() + w2 + x * w2;
y = anchorBounds.getMinY() + h2 + y * h2;
return new DiagramCoordinate(x, y);
}
/** Returns the {@link EOrientation} for the given {@link Side}. */
public static EOrientation convertSideToEOrientation(Side s) {
switch(s) {
case TOP:
return EOrientation.NORTH;
case BOTTOM:
return EOrientation.SOUTH;
case LEFT:
return EOrientation.WEST;
case RIGHT:
return EOrientation.EAST;
}
return null;
}
/** Returns the {@link Side} for the given {@link EOrientation}. */
public static Side convertEOrientationToSide(EOrientation eo) {
switch(eo) {
case NORTH:
return Side.TOP;
case SOUTH:
return Side.BOTTOM;
case WEST:
return Side.LEFT;
case EAST:
return Side.RIGHT;
}
return null;
}
/** Constructor. */
private LWFXEditorUtils() {
// prevent instantiation
}
}
No preview for this file type
......@@ -7,7 +7,7 @@ EReferencePropertySectionBase.java 0548da6778516003257f59d0b4c2b60d458be3b6 GREE
EditorBase.java 9c09fff92945256bb8680992ae7bb2c78f47b150 GREEN
FXEditorBase.java 2e520be0bbae7d0aebdff70218a124dbe0896ce2 GREEN
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java 5c53864d395ec15a0b31fa4e33cc5384d01d6f0a RED
LWFXEFEditorBase.java 0b8e6af85d83d0542dcd908974e52c618bc22a08 YELLOW
ModelEditorBindingBase.java 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN
ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
......
......@@ -50,14 +50,9 @@ public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T
/** {@inheritDoc} */
@Override
// TODO(AD): Avoid curly braces in lambdas for single statements.
protected final Parent createSceneRoot() {
viewer = new DiagramViewer(createModelFactory(), createVisualFactory(),
createControllerFactory(), cb -> {
modelSelected();
}, chg -> {
applyModelChange(chg);
});
createControllerFactory(), cb -> modelSelected(), chg -> applyModelChange(chg));
customizeViewer();
getSite().setSelectionProvider(this);
return viewer.getVisualNode();
......@@ -84,10 +79,7 @@ public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T
/** Called when some change to the model happens. */
protected void applyModelChange(Change chg) {
// TODO(AD): Avoid curly braces in lambdas for single statements.
ICommandStackService.getInstance().runAsCommand(editedObject, () -> {
chg.applyChange();
});
ICommandStackService.getInstance().runAsCommand(editedObject, () -> chg.applyChange());
}
/** {@inheritDoc} */
......@@ -120,7 +112,6 @@ public abstract class LWFXEFEditorBase<T extends EObject> extends FXEditorBase<T
}
/** Creates an {@link IStructuredSelection} from {@link DiagramViewerSelection}. */
// TODO(AD): Can't this be put directly in the getSelection method?
private IStructuredSelection createSelection() {
DiagramViewerSelection vsel = viewer.getSelection();
if(vsel.isEmpty()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment