use of org.eclipse.nebula.treemapper.internal.LinkFigure in project InformationSystem by ObeoNetwork.
the class TreeMapper method setSelection.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
*/
public void setSelection(ISelection selection) {
IStructuredSelection strSelection = (IStructuredSelection) selection;
if (strSelection.isEmpty()) {
// Deselect all figures and mappings
currentSelection = new StructuredSelection();
for (M selectedMapping : selectedMappings) {
applyDefaultMappingStyle(mappingsToFigures.get(selectedMapping));
}
selectedFigures.clear();
selectedMappings.clear();
} else {
currentSelection = strSelection;
// Deselect previously selected mappings
List<M> previouslySelectedMappings = new ArrayList<M>(selectedMappings);
for (M previouslySelectedMapping : previouslySelectedMappings) {
LinkFigure arrowFigure = mappingsToFigures.get(previouslySelectedMapping);
if (!strSelection.toList().contains(previouslySelectedMapping)) {
selectedFigures.remove(arrowFigure);
selectedMappings.remove(previouslySelectedMapping);
applyDefaultMappingStyle(arrowFigure);
}
}
// Display new selected mappings
for (Object newSelectedObject : strSelection.toList()) {
@SuppressWarnings("unchecked") M newSelectedMapping = (M) newSelectedObject;
if (!selectedMappings.contains(newSelectedMapping)) {
LinkFigure arrowFigure = mappingsToFigures.get(newSelectedMapping);
selectedFigures.add(arrowFigure);
selectedMappings.add(newSelectedMapping);
applySelectedMappingFeedback(arrowFigure);
}
}
}
// Notify listeners that the selection changed
for (ISelectionChangedListener listener : selectionChangedListeners) {
listener.selectionChanged(new SelectionChangedEvent(this, currentSelection));
}
}
use of org.eclipse.nebula.treemapper.internal.LinkFigure in project InformationSystem by ObeoNetwork.
the class TreeMapper method drawMapping.
/**
* @param leftItem
* @param rightItem
*/
private void drawMapping(final M mapping) {
LinkFigure previousFigure = mappingsToFigures.get(mapping);
if (previousFigure != null) {
previousFigure.deleteFromParent();
mappingsToFigures.remove(mapping);
figuresToMappings.remove(previousFigure);
}
boolean leftItemVisible = true;
TreeItem leftTreeItem = (TreeItem) leftTreeViewer.testFindItem(semanticSupport.resolveLeftItem(mapping));
TreeItem lastVisibleLeftTreeItem = leftTreeItem;
if (leftTreeItem != null) {
while (leftTreeItem.getParentItem() != null) {
if (!leftTreeItem.getParentItem().getExpanded()) {
lastVisibleLeftTreeItem = leftTreeItem.getParentItem();
leftItemVisible = false;
}
leftTreeItem = leftTreeItem.getParentItem();
}
}
boolean rightItemVisible = true;
TreeItem rightTreeItem = (TreeItem) rightTreeViewer.testFindItem(semanticSupport.resolveRightItem(mapping));
TreeItem lastVisibleRightTreeItem = rightTreeItem;
if (rightTreeItem != null) {
while (rightTreeItem.getParentItem() != null) {
if (!rightTreeItem.getParentItem().getExpanded()) {
lastVisibleRightTreeItem = rightTreeItem.getParentItem();
rightItemVisible = false;
}
rightTreeItem = rightTreeItem.getParentItem();
}
}
if (lastVisibleLeftTreeItem == null || lastVisibleRightTreeItem == null) {
return;
}
final LinkFigure arrowFigure = new LinkFigure(linkRootFigure);
// store it
figuresToMappings.put(arrowFigure, mapping);
mappingsToFigures.put(mapping, arrowFigure);
arrowFigure.setLeftPoint(0, lastVisibleLeftTreeItem.getBounds().y + lastVisibleLeftTreeItem.getBounds().height / 2);
arrowFigure.setLeftMappingVisible(leftItemVisible);
arrowFigure.setRightPoint(linkRootFigure.getBounds().width, lastVisibleRightTreeItem.getBounds().y + rightTreeItem.getBounds().height / 2);
arrowFigure.setRightMappingVisible(rightItemVisible);
arrowFigure.setLineWidth(uiConfig.getDefaultArrowWidth());
arrowFigure.seLineColor(uiConfig.getDefaultMappingColor());
arrowFigure.addMouseListener(new MouseListener() {
public void mousePressed(MouseEvent me) {
boolean addToSelection = ((me.getState() & SWT.CONTROL) > 0);
fireMappingSelection(mapping, arrowFigure, addToSelection);
}
public void mouseReleased(MouseEvent me) {
}
public void mouseDoubleClicked(MouseEvent me) {
// if (arrowFigure.)
}
});
arrowFigure.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent me) {
}
public void mouseEntered(MouseEvent me) {
fireMouseEntered(mapping, arrowFigure);
}
public void mouseExited(MouseEvent me) {
fireMouseExited(mapping, arrowFigure);
}
public void mouseHover(MouseEvent me) {
}
public void mouseMoved(MouseEvent me) {
}
});
}
use of org.eclipse.nebula.treemapper.internal.LinkFigure in project InformationSystem by ObeoNetwork.
the class TreeMapper method deleteMapping.
private void deleteMapping(M mapping) {
LinkFigure figure = mappingsToFigures.get(mapping);
mappings.remove(mapping);
selectedMappings.remove(mapping);
mappingsToFigures.remove(mapping);
selectedFigures.remove(figure);
figuresToMappings.remove(figure);
semanticSupport.deleteSemanticMappingObject(mapping);
if (figure != null) {
figure.deleteFromParent();
}
refresh();
for (IDeletedMappingListener<M> listener : deletionListeners) {
listener.mappingDeleted(mapping);
}
setSelection(new StructuredSelection());
}
use of org.eclipse.nebula.treemapper.internal.LinkFigure in project InformationSystem by ObeoNetwork.
the class TreeMapper method redrawMappings.
/**
* DO NOT USE IN CODE. Prefer setting "canvasNeedsRedraw" field to true to
* avoid useless operations.
* @param mappings
*/
private void redrawMappings() {
if (this.mappings == null || this.mappings.size() == 0) {
return;
}
for (M mapping : this.mappings) {
drawMapping(mapping);
selectedFigures.clear();
if (selectedMappings.contains(mapping)) {
LinkFigure newSelectedFigure = mappingsToFigures.get(mapping);
applySelectedMappingFeedback(newSelectedFigure);
selectedFigures.add(newSelectedFigure);
}
}
}
Aggregations