Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
create a collapsible tool group per dictionary
Browse files Browse the repository at this point in the history
support reorder of metablocks and form inputs
support drop of metablocks into forms in specific positions
try adding back compartment insets to get rid of scrollbars
  • Loading branch information
gregjan committed Jun 27, 2012
1 parent 5beb934 commit ae5e849
Show file tree
Hide file tree
Showing 25 changed files with 813 additions and 432 deletions.
10 changes: 5 additions & 5 deletions crosswalk-gmf.diagram/messages.properties
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ InputField2CreationTool_title=Input Field
InputField2CreationTool_desc=Add an input field to a metadata block InputField2CreationTool_desc=Add an input field to a metadata block
CrossWalkModelBoxCompartmentEditPart_title=ModelBoxCompartment CrossWalkModelBoxCompartmentEditPart_title=ModelBoxCompartment
DictionaryModelBoxCompartmentEditPart_title=ModelBoxCompartment DictionaryModelBoxCompartmentEditPart_title=ModelBoxCompartment
MetadataBlockMetadataBlockInputFieldsCompartmentEditPart_title=input MetadataBlockMetadataBlockInputFieldsCompartmentEditPart_title=inputs
MetadataBlockMetadataBlockMappingCompartmentEditPart_title=map MetadataBlockMetadataBlockMappingCompartmentEditPart_title=mapping
NavigatorGroupName_DateRecognizer_3019_incominglinks=incoming links NavigatorGroupName_DateRecognizer_3019_incominglinks=incoming links
NavigatorGroupName_DateRecognizer_3019_outgoinglinks=outgoing links NavigatorGroupName_DateRecognizer_3019_outgoinglinks=outgoing links
NavigatorGroupName_OriginalNameRecordMatcher_3018_outgoinglinks=outgoing links NavigatorGroupName_OriginalNameRecordMatcher_3018_outgoinglinks=outgoing links
Expand Down Expand Up @@ -240,11 +240,11 @@ NavigatorGroupName_OriginalNameRecordMatcher_3011_outgoinglinks=outgoing links
NavigatorGroupName_TrimWhitespace_3014_incominglinks=incoming links NavigatorGroupName_TrimWhitespace_3014_incominglinks=incoming links
NavigatorGroupName_TrimWhitespace_3014_outgoinglinks=outgoing links NavigatorGroupName_TrimWhitespace_3014_outgoinglinks=outgoing links
MetadataBlockMetadataBlockInputFieldsCompartment2EditPart_title=inputs MetadataBlockMetadataBlockInputFieldsCompartment2EditPart_title=inputs
MetadataBlockMetadataBlockMappingCompartment2EditPart_title=map MetadataBlockMetadataBlockMappingCompartment2EditPart_title=mapping
DictionaryTools2Group_title=Dictionary Tools DictionaryTools2Group_title=Dictionary Tools
FormandDictionary2Group_title=Form and Dictionary FormandDictionary2Group_title=Form and Dictionary
Paragraph3CreationTool_title=Paragraph Paragraph3CreationTool_title=Paragraph
Paragraph3CreationTool_desc=A block of text with optional header used in forms. Paragraph3CreationTool_desc=A block of text with optional header used in forms.
FormModelBoxCompartmentEditPart_title=ModelBoxCompartment FormModelBoxCompartmentEditPart_title=ModelBoxCompartment
MetadataBlockMetadataBlockInputFieldsCompartment3EditPart_title=MetadataBlockInputFieldsCompartment MetadataBlockMetadataBlockInputFieldsCompartment3EditPart_title=inputs
MetadataBlockMetadataBlockMappingCompartment3EditPart_title=MetadataBlockMappingCompartment MetadataBlockMetadataBlockMappingCompartment3EditPart_title=mapping
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,34 @@
package crosswalk.diagram.custom;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.util.Assert;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;

public class CompartmentChildCreateCommand extends CreateCommand {
int index;

public CompartmentChildCreateCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor,
View containerView, int index) {
super(editingDomain, viewDescriptor, containerView);
this.index = index;
}

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

View view = ViewService.getInstance().createView(viewDescriptor.getViewKind(),
viewDescriptor.getElementAdapter(), containerView, viewDescriptor.getSemanticHint(), index,
viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint());
Assert.isNotNull(view, "failed to create a view"); //$NON-NLS-1$
viewDescriptor.setView(view);

return CommandResult.newOKCommandResult(viewDescriptor);
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,112 @@
package crosswalk.diagram.custom;

import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.geometry.Transposer;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.DropRequest;
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;

public class CompartmentChildCreationEditPolicy extends CreationEditPolicy {
@Override
protected Command getCreateCommand(CreateViewRequest request) {
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain,
DiagramUIMessages.AddCommand_Label);

Iterator descriptors = request.getViewDescriptors().iterator();

while (descriptors.hasNext()) {
CreateViewRequest.ViewDescriptor descriptor = (CreateViewRequest.ViewDescriptor) descriptors.next();

CreateCommand createCommand = new CompartmentChildCreateCommand(editingDomain, descriptor,
(View) (getHost().getModel()), getFeedbackIndexFor(request));

cc.compose(createCommand);
}
return new ICommandProxy(cc.reduce());
}

protected int getFeedbackIndexFor(Request request) {
List children = getHost().getChildren();
if (children.isEmpty())
return -1;

Transposer transposer = new Transposer();
transposer.setEnabled(!isHorizontal());

Point p = transposer.t(getLocationFromRequest(request));

// Current row bottom, initialize to above the top.
int rowBottom = Integer.MIN_VALUE;
int candidate = -1;
for (int i = 0; i < children.size(); i++) {
EditPart child = (EditPart) children.get(i);
Rectangle rect = transposer.t(getAbsoluteBounds(((GraphicalEditPart) child)));
if (rect.y > rowBottom) {
/*
* We are in a new row, so if we don't have a candidate but yet are within the previous row, then the
* current entry becomes the candidate. This is because we know we must be to the right of center of the
* last Figure in the previous row, so this Figure (which is at the start of a new row) is the candidate.
*/
if (p.y <= rowBottom) {
if (candidate == -1)
candidate = i;
break;
} else
candidate = -1; // Mouse's Y is outside the row, so reset the candidate
}
rowBottom = Math.max(rowBottom, rect.bottom());
if (candidate == -1) {
/*
* See if we have a possible candidate. It is a candidate if the cursor is left of the center of this
* candidate.
*/
if (p.x <= rect.x + (rect.width / 2))
candidate = i;
}
if (candidate != -1) {
// We have a candidate, see if the rowBottom has grown to include the mouse Y.
if (p.y <= rowBottom) {
/*
* Now we have determined that the cursor.Y is above the bottom of the current row of figures. Stop now,
* to prevent the next row from being searched
*/
break;
}
}
}
return candidate;
}

protected boolean isHorizontal() {
IFigure figure = ((GraphicalEditPart) getHost()).getContentPane();
return ((FlowLayout) figure.getLayoutManager()).isHorizontal();
}

private Point getLocationFromRequest(Request request) {
return ((DropRequest) request).getLocation();
}

private Rectangle getAbsoluteBounds(GraphicalEditPart ep) {
Rectangle bounds = ep.getFigure().getBounds().getCopy();
ep.getFigure().translateToAbsolute(bounds);
return bounds;
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,39 @@
package crosswalk.diagram.custom;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand;
import org.eclipse.gmf.runtime.notation.View;

public class CompartmentRepositionEObjectCommand extends RepositionEObjectCommand {
EditPart childToMove = null;
int newIndex = 0;

public CompartmentRepositionEObjectCommand(TransactionalEditingDomain editingDomain, String label, EList elements,
EObject element, int displacement) {
super(editingDomain, label, elements, element, displacement);
}

public CompartmentRepositionEObjectCommand(EditPart childToMove, TransactionalEditingDomain editingDomain,
String label, EList elements, EObject element, int displacement, int newIndex) {
super(editingDomain, label, elements, element, displacement);
this.childToMove = childToMove;
this.newIndex = newIndex;
}

public CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
throws ExecutionException {
CommandResult rs = super.doExecuteWithResult(progressMonitor, info);
EditPart compartment = childToMove.getParent();
ViewUtil.repositionChildAt((View) compartment.getModel(), (View) childToMove.getModel(), newIndex);
compartment.refresh();
return rs;
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,96 @@
package crosswalk.diagram.custom;

import org.eclipse.draw2d.PositionConstants;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.diagram.core.commands.AddCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.FlowLayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
import org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.View;

public class ReorderCompartmentEditPolicy extends FlowLayoutEditPolicy {
private EStructuralFeature feature = null;

public ReorderCompartmentEditPolicy(EStructuralFeature feature) {
super();
this.feature = feature;
}

@Override
protected Command createAddCommand(EditPart child, EditPart after) {
int index = getHost().getChildren().indexOf(after);
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
AddCommand command = new AddCommand(editingDomain, new EObjectAdapter((View)getHost().getModel()),
new EObjectAdapter((View)child.getModel()), index);
return new ICommandProxy(command);
}

@Override
protected Command createMoveChildCommand(EditPart child, EditPart after) {

int newIndex;
int displacement;

int childIndex = getHost().getChildren().indexOf(child);
int afterIndex = getHost().getChildren().indexOf(after);

if(afterIndex == -1) {
newIndex = getHost().getChildren().size()-1;
displacement = newIndex - childIndex;
} else {
newIndex = afterIndex;
displacement = afterIndex - childIndex;
if (childIndex <= afterIndex) {
newIndex--;
displacement--;
}
}


TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();

RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(child, editingDomain, "",
(EList)((View)child.getParent().getModel()).getElement().eGet(feature),
((View)child.getModel()).getElement(),
displacement, newIndex);

//TODO ev. reintroduce target feedback (actual problem: line is not deleted after dropping)
eraseLayoutTargetFeedback(null);

return new ICommandProxy(command);
}

@Override
protected EditPolicy createChildEditPolicy(EditPart child) {
ResizableEditPolicyEx policy = new ResizableEditPolicyEx();
//policy.setResizeDirections(PositionConstants.EAST_WEST);
policy.setResizeDirections(0);
return policy;
}

@Override
protected Command getCreateCommand(CreateRequest request) {
return null;
}

@Override
protected Command getDeleteDependantCommand(Request request) {
return null;
}

@Override
protected Command getOrphanChildrenCommand(Request request) {
return null;
}

}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void createContents() {


ToolbarLayout layoutFFigureFlowModelBox = new ToolbarLayout(); ToolbarLayout layoutFFigureFlowModelBox = new ToolbarLayout();
layoutFFigureFlowModelBox.setStretchMinorAxis(false); layoutFFigureFlowModelBox.setStretchMinorAxis(false);
layoutFFigureFlowModelBox.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); layoutFFigureFlowModelBox.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);


layoutFFigureFlowModelBox.setSpacing(5); layoutFFigureFlowModelBox.setSpacing(5);
layoutFFigureFlowModelBox.setVertical(true); layoutFFigureFlowModelBox.setVertical(true);
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,16 +1,20 @@
package crosswalk.diagram.edit.parts; package crosswalk.diagram.edit.parts;


import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure; import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.notation.View; import org.eclipse.gmf.runtime.notation.View;


import crosswalk.CrosswalkPackage;
import crosswalk.diagram.custom.CompartmentChildCreationEditPolicy;
import crosswalk.diagram.custom.ReorderCompartmentEditPolicy;
import crosswalk.diagram.edit.policies.FormModelBoxCompartmentCanonicalEditPolicy; import crosswalk.diagram.edit.policies.FormModelBoxCompartmentCanonicalEditPolicy;
import crosswalk.diagram.edit.policies.FormModelBoxCompartmentItemSemanticEditPolicy; import crosswalk.diagram.edit.policies.FormModelBoxCompartmentItemSemanticEditPolicy;
import crosswalk.diagram.part.Messages; import crosswalk.diagram.part.Messages;
Expand Down Expand Up @@ -47,23 +51,32 @@ public String getCompartmentName() {
} }


/** /**
* @generated * @generated NOT
*/ */
public IFigure createFigure() { public IFigure createFigure() {
ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure(); ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
FlowLayout layout = new FlowLayout();
layout.setMajorSpacing(getMapMode().DPtoLP(5));
layout.setMinorSpacing(getMapMode().DPtoLP(5));
layout.setHorizontal(false);

result.getContentPane().setLayoutManager(layout);
result.setTitleVisibility(false); result.setTitleVisibility(false);
return result; return result;
} }


/** /**
* @generated * @generated NOT
*/ */
protected void createDefaultEditPolicies() { protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies(); super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new FormModelBoxCompartmentItemSemanticEditPolicy()); installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new FormModelBoxCompartmentItemSemanticEditPolicy());
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy()); //installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new FormModelBoxCompartmentCanonicalEditPolicy()); installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new FormModelBoxCompartmentCanonicalEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderCompartmentEditPolicy(
CrosswalkPackage.Literals.FORM__ELEMENTS));
} }


/** /**
Expand Down
Loading

0 comments on commit ae5e849

Please sign in to comment.