Skip to content

Commit

Permalink
Final feature: you can add several classes together, filter classes t…
Browse files Browse the repository at this point in the history
…o add and show members of a particular component
  • Loading branch information
fdodino committed Jul 25, 2017
1 parent 738dc0d commit 2f4ec94
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class Messages extends NLS {
public static String StaticDiagram_CleanAllRelationships_Description;
public static String StaticDiagram_ShowHiddenComponents_Description;
public static String StaticDiagram_ShowHiddenParts_Description;
public static String StaticDiagram_ShowHiddenPartsElement_Description;
public static String StaticDiagram_AddOutsiderClass_Description;
public static String StaticDiagram_AddOutsiderClass_WindowTitle;
public static String StaticDiagram_AddOutsiderClass_AcceptButton;
public static String StaticDiagram_AddOutsiderClass_CancelButton;
public static String StaticDiagram_DeleteAllOutsiderClasses_Description;

// Tool entries
public static String StaticDiagram_CreateAssociation_Title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StaticDiagramBuilder {

List<WMethodContainer> allElements
List<WMixin> allMixins
List<WNamedObject> allSingleObjects

new() {
init
Expand All @@ -30,6 +31,7 @@ class StaticDiagramBuilder {
def void init() {
allElements = newArrayList
allMixins = newArrayList
allSingleObjects = newArrayList
}

def dispatch StaticDiagramBuilder addElements(List<? extends WMethodContainer> elements) {
Expand All @@ -47,10 +49,22 @@ class StaticDiagramBuilder {
}
this
}


def dispatch void addToRightCollection(WNamedObject o) {
if (o.hasRealParent) {
allElements.add(o)
} else {
allSingleObjects.add(o)
}
}

def dispatch void addToRightCollection(WMethodContainer mc) {
allElements.add(mc)
}

def dispatch StaticDiagramBuilder addElement(WMethodContainer m) {
if (!allElements.map [ identifier ].contains(m.identifier)) {
allElements.add(m)
m.addToRightCollection
m.doAddElement
m.mixins.forEach [ addElement ]
}
Expand All @@ -72,4 +86,5 @@ class StaticDiagramBuilder {

def allMixins() { allMixins }

def allSingleObjects() { allSingleObjects }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.util.Observable
import org.eclipse.core.resources.IResource
import org.eclipse.draw2d.geometry.Dimension
import org.eclipse.draw2d.geometry.Point
import org.eclipse.emf.common.util.URI
import org.eclipse.osgi.util.NLS
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.Data
Expand Down Expand Up @@ -70,12 +71,6 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
internalInitOutsiderElements
}

def void initLocationsAndSizes() {
this.internalInitLocationsAndSizes
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void internalInitLocationsAndSizes() {
locations = newHashMap
sizes = newHashMap
Expand All @@ -85,18 +80,6 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
outsiderElements = newArrayList
}

def void showAllComponents() {
this.internalInitHiddenComponents
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def showAllParts() {
this.internalInitHiddenParts
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void internalInitHiddenComponents() {
hiddenComponents = newArrayList
}
Expand All @@ -105,12 +88,6 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
hiddenParts = newHashMap
}

def void initRelationships() {
this.internalInitRelationships
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void internalInitRelationships() {
relations = newArrayList
}
Expand All @@ -121,6 +98,44 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
* CONFIGURATION CHANGES
*******************************************************
*/

def void initRelationships() {
this.internalInitRelationships
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void initLocationsAndSizes() {
this.internalInitLocationsAndSizes
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void showAllComponents() {
this.internalInitHiddenComponents
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def showAllPartsFrom(AbstractModel model) {
hiddenParts.remove(model.label)
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}


def showAllParts() {
this.internalInitHiddenParts
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void initOutsiderElements() {
this.internalInitOutsiderElements
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def void saveLocation(Shape shape) {
if (!rememberLocationAndSizeShapes) return;
locations.put(shape.toString, new Point => [
Expand All @@ -140,11 +155,20 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
}

def hideComponent(AbstractModel model) {
hiddenComponents.add(model.label)
val outsiderElement = model.component.outsiderElement
if (outsiderElement !== null) {
outsiderElements.remove(outsiderElement)
} else {
hiddenComponents.add(model.label)
}
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

def getOutsiderElement(WMethodContainer mc) {
outsiderElements.findFirst [ outsiderElement | outsiderElement.pointsTo(mc) ]
}

def hidePart(AbstractModel model, String partName, boolean isVariable) {
val _hiddenParts = hiddenParts.get(model.label) ?: newArrayList
_hiddenParts.add(new HiddenPart(isVariable, partName))
Expand Down Expand Up @@ -196,11 +220,11 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
}

def addOutsiderElement(WMethodContainer element) {
outsiderElements.add(new OutsiderElement(element.eResource.URI.toString, element.identifier))
outsiderElements.add(new OutsiderElement(element))
this.setChanged
this.notifyObservers(CONFIGURATION_CHANGED)
}

/**
* Fired each time you click on a xtext document
* If resource changed, configuration should clean up its state
Expand Down Expand Up @@ -384,6 +408,9 @@ class StaticDiagramConfiguration extends Observable implements Serializable {
append(" sizes = ")
append(this.sizes)
append("\n")
append(" outsiderElements = ")
append(this.outsiderElements)
append("\n")
append("}")
]
result.toString
Expand All @@ -410,8 +437,28 @@ class HiddenPart implements Serializable {
String name
}

@Data
@Accessors
class OutsiderElement implements Serializable {
String URI
String internalURI
String identifier
}

new() { }

new(WMethodContainer mc) {
internalURI = mc.eResource.URI.toString
identifier = mc.identifier
}

def pointsTo(WMethodContainer mc) {
mc.eResource.URI.toString.equals(internalURI) && mc.identifier.equals(identifier)
}

def getRealURI() {
URI.createURI(this.internalURI)
}

override toString() {
internalURI + " => " + identifier
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.eclipse.jface.action.IMenuManager
import org.eclipse.ui.actions.ActionFactory

import static org.eclipse.gef.ui.actions.GEFActionConstants.*
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.ShowHiddenPartsElementAction

/**
*
Expand All @@ -27,7 +28,8 @@ class StaticDiagramEditorContextMenuProvider extends ContextMenuProvider {

override buildContextMenu(IMenuManager it) {
addStandardActionGroups(it)
addToGroup(GROUP_EDIT, ActionFactory.DELETE.id)
addToGroup(GROUP_EDIT, ActionFactory.DELETE.id)
addToGroup(GROUP_EDIT, ShowHiddenPartsElementAction.SHOW_HIDDEN_PART_ELEMENT_ID)
}

def getAction(String actionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.eclipse.draw2d.graph.DirectedGraph
import org.eclipse.draw2d.graph.DirectedGraphLayout
import org.eclipse.draw2d.graph.Edge
import org.eclipse.draw2d.graph.Node
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.EObject
import org.eclipse.gef.DefaultEditDomain
import org.eclipse.gef.EditPart
Expand Down Expand Up @@ -70,6 +69,7 @@ import org.uqbar.project.wollok.ui.diagrams.Messages
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.AddOutsiderClass
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.CleanAllRelashionshipsAction
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.CleanShapePositionsAction
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.DeleteAllOutsiderClasses
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.DeleteElementAction
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.ExportAction
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.RememberShapePositionsToggleButton
Expand Down Expand Up @@ -99,6 +99,7 @@ import org.uqbar.project.wollok.wollokDsl.WollokDslPackage

import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.*
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import org.uqbar.project.wollok.ui.diagrams.classes.actionbar.ShowHiddenPartsElementAction

/**
*
Expand Down Expand Up @@ -171,34 +172,31 @@ class StaticDiagramView extends ViewPart implements ISelectionListener, ISourceV
// hierarchy level
// all classes and named objects inheriting from a class
// new way: instead of adding imports we just detect them because of hierarchy
// val importedClasses = xtextDocument.readOnly [ getImportedClasses ]
val inheritingObjects = objects.filter [ hasRealParent ]
val classes = xtextDocument.readOnly[ classes ]
val mapOutsiderMethodContainers = configuration.resource.project.mapMethodContainers
val outsiderClasses = configuration.outsiderElements.map [ outsiderElement |
val uriFile = URI.createURI(outsiderElement.URI)
mapOutsiderMethodContainers.get(uriFile)?.findFirst [
val outsiderElements = configuration.outsiderElements.map [ outsiderElement |
mapOutsiderMethodContainers.get(outsiderElement.realURI)?.findFirst [
outsiderElement.identifier.equals(it.identifier)
]
].filter [ it !== null ].toList

// Now let's collect all elements
val staticDiagramBuilder = new StaticDiagramBuilder()
.addElements(mixins)
.addElements(objects)
.addElements(classes)
.addElements(outsiderClasses)
.addElements(inheritingObjects)
.addElements(outsiderElements)

val allHierarchyElements = staticDiagramBuilder.allElements

ClassModel.init(allHierarchyElements)

// Drawing the Static Diagram
// First isolated Objects without parents
val singleObjects = objects.filter [ !hasRealParent && !configuration.isHiddenComponent(name) ]
val singleObjects = staticDiagramBuilder.allSingleObjects.filter [ !configuration.isHiddenComponent(name) ]

singleObjects.forEach[ o |
addNamedObject(new NamedObjectModel(o) => [
addNamedObject(new NamedObjectModel(o as WNamedObject) => [
locate
])
]
Expand Down Expand Up @@ -329,7 +327,9 @@ class StaticDiagramView extends ViewPart implements ISelectionListener, ISourceV
add(new CleanAllRelashionshipsAction(Messages.StaticDiagram_CleanAllRelationships_Description, configuration))
add(new ShowHiddenComponents(Messages.StaticDiagram_ShowHiddenComponents_Description, configuration))
add(new ShowHiddenParts(Messages.StaticDiagram_ShowHiddenParts_Description, configuration))
add(new Separator)
add(new AddOutsiderClass(Messages.StaticDiagram_AddOutsiderClass_Description, configuration))
add(new DeleteAllOutsiderClasses(Messages.StaticDiagram_DeleteAllOutsiderClasses_Description, configuration))
// In a future could remain as options: "Open External wsdi" & "Save As..."
// add(new LoadStaticDiagramConfigurationAction(Messages.StaticDiagram_LoadConfiguration_Description, configuration, this))
// add(new SaveStaticDiagramConfigurationAction(Messages.StaticDiagram_SaveConfiguration_Description, configuration))
Expand Down Expand Up @@ -410,6 +410,7 @@ class StaticDiagramView extends ViewPart implements ISelectionListener, ISourceV
def getActionRegistry() {
if (actionRegistry === null) actionRegistry = new ActionRegistry => [
registerAction(new DeleteElementAction(this, graphicalViewer, configuration))
registerAction(new ShowHiddenPartsElementAction(this, graphicalViewer, configuration))
// Adding zoom capabilities
val zoomManager = (graphicalViewer.rootEditPart as ScalableFreeformRootEditPart).zoomManager
zoomManager.setZoomLevelContributions(#[
Expand Down
Loading

0 comments on commit 2f4ec94

Please sign in to comment.