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

Commit

Permalink
fixed minor METS validation bug on export related to structLink section
Browse files Browse the repository at this point in the history
made diagram assistant more schema aware, only prompting with valid element/attribute selections (multiplicity)
fixed double popup menu for adding XML Elements from the palette
fixed / by zero bug related to modulo operator on staging monitor
some code regenerated
fixed location of new XML elements dropped on canvas
  • Loading branch information
gregjan committed Aug 2, 2011
1 parent b90165f commit e5d0b45
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
package crosswalk.diagram.custom;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

import crosswalk.CrossWalk;
import crosswalk.MappedAttribute;
import crosswalk.MappedElement;

/**
Expand All @@ -41,11 +44,14 @@ public class MappedModelUtil {
public static List<EStructuralFeature> getChildElementFeatures(EObject parent) {
// LOG.debug("model parent:" + parent);
EClass mappedParentType = null;
List<MappedElement> elementsMappedAlready = new ArrayList<MappedElement>();
if (parent instanceof CrossWalk) {
CrossWalk cw = (CrossWalk) parent;
elementsMappedAlready.addAll((Collection<? extends MappedElement>) cw.getElements());
mappedParentType = cw.getOutputType();
} else if (parent instanceof MappedElement) {
MappedElement pe = (MappedElement) parent;
elementsMappedAlready.addAll(pe.getChildElements());
if (pe.getMappedFeature() != null) {
mappedParentType = (EClass) pe.getMappedFeature().getEType();
}
Expand All @@ -57,7 +63,17 @@ public static List<EStructuralFeature> getChildElementFeatures(EObject parent) {
throw new Error("No feature was mapped on the given parent");
}
List<EStructuralFeature> result = new ArrayList<EStructuralFeature>();
result.addAll(mappedParentType.getEAllReferences());
//result.addAll(mappedParentType.getEAllReferences());
// FIXME remove the elements that are already full
for(EStructuralFeature a : mappedParentType.getEAllReferences().toArray(new EStructuralFeature[0])) {
int count = 0;
for(MappedElement m : elementsMappedAlready) {
if(m.getMappedFeature().equals(a)) count++;
}
if(a.getUpperBound() < 0 || count < a.getUpperBound()) {
result.add(a);
}
}
return result;
}

Expand All @@ -66,12 +82,15 @@ public static List<EStructuralFeature> getChildElementFeatures(EObject parent) {
* @return
*/
public static List<EStructuralFeature> getAttributes(EObject parent) {
//System.out.println("get attributes for: "+parent);
EClass mappedParentType = null;
List<MappedAttribute> attsMappedAlready = new ArrayList<MappedAttribute>();
if (parent instanceof CrossWalk) {
CrossWalk cw = (CrossWalk) parent;
mappedParentType = cw.getOutputType();
} else if (parent instanceof MappedElement) {
MappedElement pe = (MappedElement) parent;
attsMappedAlready.addAll(pe.getAttributes());
if (pe.getMappedFeature() != null) {
mappedParentType = (EClass) pe.getMappedFeature().getEType();
}
Expand All @@ -82,7 +101,16 @@ public static List<EStructuralFeature> getAttributes(EObject parent) {
throw new Error("No feature was mapped on the given parent");
}
List<EStructuralFeature> result = new ArrayList<EStructuralFeature>();
result.addAll(mappedParentType.getEAllAttributes());
// FIXME remove the elements that are already full
for(EAttribute a : mappedParentType.getEAllAttributes().toArray(new EAttribute[0])) {
int count = 0;
for(MappedAttribute m : attsMappedAlready) {
if(m.getMappedFeature().equals(a)) count++;
}
if(a.getUpperBound() < 0 || count < a.getUpperBound()) {
result.add(a);
}
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2011 The University of North Carolina at Chapel Hill
*
* 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 crosswalk.diagram.custom;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;

import crosswalk.CrossWalk;
import crosswalk.MappedElement;
import crosswalk.diagram.providers.CrosswalkElementTypes;

/**
* @author Gregory Jansen
*
*/
public class SpecialCreationEditPolicy extends CreationEditPolicy {

@Override
public Command getCommand(Request request) {
if (understandsRequest(request)) {
if (request instanceof CreateUnspecifiedTypeRequest) {
CreateUnspecifiedTypeRequest r = (CreateUnspecifiedTypeRequest) request;
View view = (View)getHost().getModel();
EObject hostElement = ViewUtil.resolveSemanticElement(view);
CreateViewAndElementRequest chosenRequest = null;
IElementType type = null;
if(hostElement instanceof CrossWalk) {
type = CrosswalkElementTypes.MappedElement_2016;
chosenRequest = (CreateViewAndElementRequest)r.getRequestForType(type);
} else if(hostElement instanceof MappedElement) {
type = CrosswalkElementTypes.MappedElement_3015;
chosenRequest = (CreateViewAndElementRequest)r.getRequestForType(type);
}
if (chosenRequest != null) {
//chosenRequest.setLocation(r.getLocation());
//chosenRequest.setExtendedData(r.getExtendedData());
//chosenRequest.setSize(r.getSize());
//chosenRequest.setType(r.getType());
List types = new ArrayList();
types.add(type);
CreateUnspecifiedTypeRequest answerReq = new CreateUnspecifiedTypeRequest(types, chosenRequest.getViewAndElementDescriptor().getPreferencesHint() );
answerReq.setExtendedData(r.getExtendedData());
answerReq.setLocation(r.getLocation());
answerReq.setSize(r.getSize());
System.out.println("chose type: "+type);
return super.getCommand(answerReq);
}
}
return super.getCommand(request);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public MappedElement2CreateCommand(CreateElementRequest req) {
* FIXME: replace with setElementToEdit()
* @generated
*/
@Override
protected EObject getElementToEdit() {
EObject container = ((CreateElementRequest) getRequest()).getContainer();
if (container instanceof View) {
Expand All @@ -45,14 +46,15 @@ protected EObject getElementToEdit() {
/**
* @generated
*/
@Override
public boolean canExecute() {
return true;

}

/**
* @generated
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
MappedElement newElement = CrosswalkFactory.eINSTANCE.createMappedElement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public MappedElementCreateCommand(CreateElementRequest req) {

/**
* FIXME: replace with setElementToEdit()
*
* @generated
*/
@Override
Expand All @@ -50,7 +51,6 @@ protected EObject getElementToEdit() {
@Override
public boolean canExecute() {
return true;

}

/**
Expand All @@ -70,12 +70,11 @@ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable
}

/**
* @generated NOT
* @generated
*/
protected void doConfigure(MappedElement newElement, IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();

ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
configureRequest.addParameters(getRequest().getParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,9 @@
*/
package crosswalk.diagram.edit.helpers;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;

/**
* @generated
*/
public class CrossWalkEditHelper extends CrosswalkBaseEditHelper {

@Override
public List getContainedValues(EObject eContainer, EReference feature) {
// TODO Auto-generated method stub
return super.getContainedValues(eContainer, feature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import org.eclipse.gef.handles.MoveHandle;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;

import crosswalk.diagram.custom.SpecialCreationEditPolicy;
import crosswalk.diagram.edit.policies.CrossWalkCanonicalEditPolicy;
import crosswalk.diagram.edit.policies.CrossWalkItemSemanticEditPolicy;
import crosswalk.diagram.providers.CrosswalkElementTypes;

/**
* @generated
Expand Down Expand Up @@ -60,9 +64,11 @@ public CrossWalkEditPart(View view) {
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new SpecialCreationEditPolicy());
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CrossWalkItemSemanticEditPolicy());
installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new CrossWalkCanonicalEditPolicy());
//removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
//removeEditPolicy(EditPolicyRoles.CREATION_ROLE);
// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
}

@Override
Expand Down Expand Up @@ -106,4 +112,23 @@ public boolean understandsRequest(Request request) {
}
}

@Override
public Command getCommand(Request _request) {
// TODO Auto-generated method stub
if (_request instanceof CreateUnspecifiedTypeRequest) {
CreateUnspecifiedTypeRequest r = (CreateUnspecifiedTypeRequest) _request;
IElementType invalid = null;
for (Object o : r.getElementTypes()) {
IElementType e = (IElementType) o;
System.out.println(e);
if (CrosswalkElementTypes.MappedElement_3015.getId().equals(e.getId())) {
invalid = e;
}
}
// r.getElementTypes().remove(invalid);
System.out.println(r);
}
return super.getCommand(_request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.FlowLayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
Expand All @@ -33,6 +34,7 @@
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;

import crosswalk.diagram.custom.SpecialCreationEditPolicy;
import crosswalk.diagram.edit.policies.MappedElement2ItemSemanticEditPolicy;
import crosswalk.diagram.part.CrosswalkVisualIDRegistry;
import crosswalk.diagram.providers.CrosswalkElementTypes;
Expand Down Expand Up @@ -69,8 +71,8 @@ public MappedElement2EditPart(View view) {
*/
@Override
protected void createDefaultEditPolicies() {
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new SpecialCreationEditPolicy());
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new MappedElement2ItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
Expand All @@ -84,14 +86,17 @@ protected LayoutEditPolicy createLayoutEditPolicy() {

FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {

@Override
protected Command createAddCommand(EditPart child, EditPart after) {
return null;
}

@Override
protected Command createMoveChildCommand(EditPart child, EditPart after) {
return null;
}

@Override
protected Command getCreateCommand(CreateRequest request) {
return null;
}
Expand Down Expand Up @@ -123,7 +128,7 @@ protected boolean addFixedChild(EditPart childEditPart) {
}
if (childEditPart instanceof MappedElementChildElementsCompartment2EditPart) {
IFigure pane = getPrimaryShape().getChildPane();
setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
pane.add(((MappedElementChildElementsCompartment2EditPart) childEditPart).getFigure());
return true;
}
Expand All @@ -139,7 +144,7 @@ protected boolean removeFixedChild(EditPart childEditPart) {
}
if (childEditPart instanceof MappedElementChildElementsCompartment2EditPart) {
IFigure pane = getPrimaryShape().getChildPane();
setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
pane.remove(((MappedElementChildElementsCompartment2EditPart) childEditPart).getFigure());
return true;
}
Expand All @@ -149,6 +154,7 @@ protected boolean removeFixedChild(EditPart childEditPart) {
/**
* @generated
*/
@Override
protected void addChildVisual(EditPart childEditPart, int index) {
if (addFixedChild(childEditPart)) {
return;
Expand All @@ -159,6 +165,7 @@ protected void addChildVisual(EditPart childEditPart, int index) {
/**
* @generated
*/
@Override
protected void removeChildVisual(EditPart childEditPart) {
if (removeFixedChild(childEditPart)) {
return;
Expand All @@ -169,6 +176,7 @@ protected void removeChildVisual(EditPart childEditPart) {
/**
* @generated
*/
@Override
protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
if (editPart instanceof MappedElementChildElementsCompartment2EditPart) {
return getPrimaryShape().getChildPane();
Expand Down Expand Up @@ -231,6 +239,7 @@ public IFigure getContentPane() {
/**
* @generated
*/
@Override
protected void setForegroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setForegroundColor(color);
Expand All @@ -240,6 +249,7 @@ protected void setForegroundColor(Color color) {
/**
* @generated
*/
@Override
protected void setBackgroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setBackgroundColor(color);
Expand Down Expand Up @@ -277,6 +287,7 @@ public EditPart getPrimaryChildEditPart() {
/**
* @generated
*/
@Override
public EditPart getTargetEditPart(Request request) {
if (request instanceof CreateViewAndElementRequest) {
CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor()
Expand Down
Loading

0 comments on commit e5d0b45

Please sign in to comment.