Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contract editor #1102

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Export-Package: org.eclipse.fordiac.ide.application,
org.eclipse.fordiac.ide.application.policies,
org.eclipse.fordiac.ide.application.properties,
org.eclipse.fordiac.ide.application.utilities,
org.eclipse.fordiac.ide.application.widgets,
org.eclipse.fordiac.ide.application.wizards
Require-Bundle: org.eclipse.emf.ecore.editor,
org.eclipse.fordiac.ide.model,
Expand All @@ -27,7 +28,9 @@ Require-Bundle: org.eclipse.emf.ecore.editor,
org.eclipse.core.expressions,
org.eclipse.fordiac.ide.ui.errormessages,
org.eclipse.fordiac.ide.model.search,
org.eclipse.jface
org.eclipse.jface,
org.eclipse.xtext.ui,
org.eclipse.fordiac.ide.contractspec.ui
Bundle-Vendor: Eclipse 4diac
Bundle-ActivationPolicy: lazy
Bundle-Version: 3.0.0.qualifier
Expand Down
3 changes: 3 additions & 0 deletions plugins/org.eclipse.fordiac.ide.application/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ QuickFixDialog_Problems_List_Title=Problems:
QuickFixDialog_Problems_List_Location=Location
QuickFixDialog_Problems_List_Resource=Resource

ContractEditor_Title=Contract Editor
ContractEditor_OK=OK

command.followLeftConnection.name=Follow Left Connection
command.followRightConnection.name=Follow Right Connection
command.goToChild.name=Go To Child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ public final class Messages extends NLS {

public static String QuickFixDialog_Problems_List_Resource;

public static String ContractEditor_Title;

public static String ContractEditor_OK;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ protected EditPart getPartForElement(final EditPart context, final Object modelE
if (modelElement instanceof InstanceComment) {
return new InstanceCommentEditPart();
}
if (modelElement instanceof InstanceContract) {
return new InstanceContractEditPart();
}
if (modelElement instanceof Connection) {
return new ConnectionEditPart();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2025 Felix Schmid
*
* 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:
* Felix Schmid
* - initial implementation and/or documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.application.editparts;

import org.eclipse.fordiac.ide.model.commands.change.ChangeContractCommand;
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;

public class InstanceContract {

public static final String CONTRACT_ATTRIBUTE_NAME = ChangeContractCommand.CONTRACT_ATTRIBUTE_NAME;
private final SubApp subApp;

public InstanceContract(final SubApp subApp) {
this.subApp = subApp;
}

public SubApp getSubApp() {
return subApp;
}

public String getContract() {
return getSubApp().getAttributeValue(CONTRACT_ATTRIBUTE_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2025 Felix Schmid
*
* 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:
* Felix Schmid
* - initial implementation and/or documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.application.editparts;

import org.eclipse.draw2d.IFigure;
import org.eclipse.fordiac.ide.application.figures.InstanceContractFigure;
import org.eclipse.fordiac.ide.application.widgets.ContractEditorDialog;
import org.eclipse.fordiac.ide.model.commands.change.ChangeContractCommand;
import org.eclipse.fordiac.ide.ui.editors.EditorUtils;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.requests.GroupRequest;
import org.eclipse.swt.widgets.Display;

public class InstanceContractEditPart extends AbstractGraphicalEditPart {

private static final int CANCEL = -1;

private class DeleteContractEditPolicy extends org.eclipse.gef.editpolicies.ComponentEditPolicy {
@Override
protected Command createDeleteCommand(final GroupRequest request) {
return new ChangeContractCommand(getModel().getSubApp(), null);
}
}

void refreshValue() {
getFigure().setText(getModel().getContract());
}

@Override
public void refresh() {
super.refresh();
refreshValue();
}

@Override
public InstanceContractFigure getFigure() {
return (InstanceContractFigure) super.getFigure();
}

@Override
protected void createEditPolicies() {
// for deleting a contract
installEditPolicy(EditPolicy.COMPONENT_ROLE, new DeleteContractEditPolicy());
}

@Override
public InstanceContract getModel() {
return (InstanceContract) super.getModel();
}

@Override
protected IFigure createFigure() {
return new InstanceContractFigure(getModel().getContract());
}

@Override
public void performRequest(final Request request) {
// REQ_DIRECT_EDIT -> first select 0.4 sec pause -> click -> edit
// REQ_OPEN -> doubleclick

final CommandStack cmdStack = EditorUtils.getCurrentActiveEditor().getAdapter(CommandStack.class);

if (((request.getType() == RequestConstants.REQ_DIRECT_EDIT)
|| (request.getType() == RequestConstants.REQ_OPEN)) && cmdStack != null) {
performDirectEdit(cmdStack);
} else {
super.performRequest(request);
}
}

private void performDirectEdit(final CommandStack cmdStack) {
final var shell = Display.getCurrent().getActiveShell();
final var editor = new ContractEditorDialog(shell, getModel().getContract());

if (editor.open() != CANCEL) {
cmdStack.execute(new ChangeContractCommand(getModel().getSubApp(), editor.getContractRule()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
import org.eclipse.swt.widgets.Display;

public class SubAppForFBNetworkEditPart extends AbstractFBNElementEditPart implements IContainerEditPart {

private final ExpandedInterfacePositionMap positionMap = new ExpandedInterfacePositionMap(this);
private InstanceContract instanceContract;

@Override
public Adapter createContentAdapter() {
Expand Down Expand Up @@ -209,6 +211,9 @@ protected void revertOldEditValue(final DirectEditRequest request) {
@Override
protected List<Object> getModelChildren() {
final List<Object> children = super.getModelChildren();
if (getModel().isUnfolded() && getModel().getAttribute(InstanceContract.CONTRACT_ATTRIBUTE_NAME) != null) {
children.add(getInstanceContract());
}
if (getModel().isUnfolded()) {
children.add(getModel().getSubAppNetwork());
}
Expand All @@ -219,6 +224,13 @@ public SubAppForFBNetworkEditPart() {
// nothing to do here
}

public InstanceContract getInstanceContract() {
if (instanceContract == null) {
instanceContract = new InstanceContract(getModel());
}
return instanceContract;
}

@Override
protected IFigure createFigureForModel() {
return new SubAppForFbNetworkFigure(getModel(), this);
Expand Down
Loading
Loading