Lines 33-38
Link Here
|
33 |
import org.eclipse.draw2d.geometry.Dimension; |
33 |
import org.eclipse.draw2d.geometry.Dimension; |
34 |
import org.eclipse.draw2d.geometry.Point; |
34 |
import org.eclipse.draw2d.geometry.Point; |
35 |
import org.eclipse.draw2d.geometry.Rectangle; |
35 |
import org.eclipse.draw2d.geometry.Rectangle; |
|
|
36 |
import org.eclipse.jface.viewers.CellEditor; |
37 |
import org.eclipse.jface.viewers.ICellEditorListener; |
36 |
import org.eclipse.swt.SWT; |
38 |
import org.eclipse.swt.SWT; |
37 |
import org.eclipse.swt.events.PaintEvent; |
39 |
import org.eclipse.swt.events.PaintEvent; |
38 |
import org.eclipse.swt.events.PaintListener; |
40 |
import org.eclipse.swt.events.PaintListener; |
Lines 57-63
Link Here
|
57 |
import org.eclipse.zest.layouts.constraints.LayoutConstraint; |
59 |
import org.eclipse.zest.layouts.constraints.LayoutConstraint; |
58 |
|
60 |
|
59 |
/* |
61 |
/* |
60 |
* Holds the nodes and connections for the graph. |
62 |
* * Holds the nodes and connections for the graph. |
61 |
* |
63 |
* |
62 |
* @author Chris Callendar |
64 |
* @author Chris Callendar |
63 |
* |
65 |
* |
Lines 108-113
Link Here
|
108 |
private ScalableFreeformLayeredPane rootlayer; |
110 |
private ScalableFreeformLayeredPane rootlayer; |
109 |
private ZestRootLayer zestRootLayer; |
111 |
private ZestRootLayer zestRootLayer; |
110 |
|
112 |
|
|
|
113 |
/** Listen CellEditor behavior */ |
114 |
private InnerCellEditorListener cellEditorListener = null; |
115 |
|
111 |
/** |
116 |
/** |
112 |
* Constructor for a Graph. This widget represents the root of the graph, |
117 |
* Constructor for a Graph. This widget represents the root of the graph, |
113 |
* and can contain graph items such as graph nodes and graph connections. |
118 |
* and can contain graph items such as graph nodes and graph connections. |
Lines 203-208
Link Here
|
203 |
} |
208 |
} |
204 |
}); |
209 |
}); |
205 |
|
210 |
|
|
|
211 |
cellEditorListener = new InnerCellEditorListener(); |
206 |
} |
212 |
} |
207 |
|
213 |
|
208 |
/** |
214 |
/** |
Lines 431-436
Link Here
|
431 |
return this.layoutAlgorithm; |
437 |
return this.layoutAlgorithm; |
432 |
} |
438 |
} |
433 |
|
439 |
|
|
|
440 |
protected void showCellEditor(GraphItem item) { |
441 |
if (!canDirectEdit(item)) { |
442 |
return; |
443 |
} |
444 |
CellEditor cellEditor = item.getCellEditor(); |
445 |
ICellEditorManager manager = item.getCellEditorManager(); |
446 |
if (cellEditor != null && manager != null) { |
447 |
cellEditor.removeListener(cellEditorListener); |
448 |
cellEditorListener.setHostItem(item); |
449 |
cellEditor.setValue(manager.getEditValue(item)); |
450 |
cellEditor.getControl().setFont(item.getFigure().getFont()); |
451 |
manager.locatCellEditor(cellEditor); |
452 |
cellEditor.addListener(cellEditorListener); |
453 |
cellEditor.activate(); |
454 |
cellEditor.getControl().setVisible(true); |
455 |
cellEditor.setFocus(); |
456 |
} |
457 |
} |
458 |
|
434 |
/** |
459 |
/** |
435 |
* Finds a figure at the location X, Y in the graph |
460 |
* Finds a figure at the location X, Y in the graph |
436 |
* |
461 |
* |
Lines 498-503
Link Here
|
498 |
Iterator iterator = selectedItems.iterator(); |
523 |
Iterator iterator = selectedItems.iterator(); |
499 |
while (iterator.hasNext()) { |
524 |
while (iterator.hasNext()) { |
500 |
GraphItem item = (GraphItem) iterator.next(); |
525 |
GraphItem item = (GraphItem) iterator.next(); |
|
|
526 |
// If start to drag item , its celleditor must be hidden. |
527 |
hideCellEditor(item); |
501 |
if ((item.getItemType() == GraphItem.NODE) || (item.getItemType() == GraphItem.CONTAINER)) { |
528 |
if ((item.getItemType() == GraphItem.NODE) || (item.getItemType() == GraphItem.CONTAINER)) { |
502 |
// @tag Zest.selection Zest.move : This is where the node movement is tracked |
529 |
// @tag Zest.selection Zest.move : This is where the node movement is tracked |
503 |
Point pointCopy = mousePoint.getCopy(); |
530 |
Point pointCopy = mousePoint.getCopy(); |
Lines 667-672
Link Here
|
667 |
selectedItems.remove(itemUnderMouse); |
694 |
selectedItems.remove(itemUnderMouse); |
668 |
(itemUnderMouse).unhighlight(); |
695 |
(itemUnderMouse).unhighlight(); |
669 |
fireWidgetSelectedEvent(itemUnderMouse); |
696 |
fireWidgetSelectedEvent(itemUnderMouse); |
|
|
697 |
} else { |
698 |
// If click the selected item , prefer to start direct edit |
699 |
showCellEditor(itemUnderMouse); |
670 |
} |
700 |
} |
671 |
return; |
701 |
return; |
672 |
} |
702 |
} |
Lines 696-717
Link Here
|
696 |
|
726 |
|
697 |
public void mouseReleased(org.eclipse.draw2d.MouseEvent me) { |
727 |
public void mouseReleased(org.eclipse.draw2d.MouseEvent me) { |
698 |
isDragging = false; |
728 |
isDragging = false; |
699 |
|
|
|
700 |
} |
729 |
} |
701 |
|
730 |
|
702 |
} |
731 |
} |
703 |
|
732 |
|
|
|
733 |
/** |
734 |
* Default return true; |
735 |
* @param item |
736 |
* @return |
737 |
*/ |
738 |
protected boolean canDirectEdit(GraphItem item) { |
739 |
return true; |
740 |
} |
741 |
|
704 |
private void clearSelection() { |
742 |
private void clearSelection() { |
705 |
if (selectedItems.size() > 0) { |
743 |
if (selectedItems.size() > 0) { |
706 |
Iterator iterator = selectedItems.iterator(); |
744 |
Iterator iterator = selectedItems.iterator(); |
707 |
while (iterator.hasNext()) { |
745 |
while (iterator.hasNext()) { |
708 |
GraphItem item = (GraphItem) iterator.next(); |
746 |
GraphItem item = (GraphItem) iterator.next(); |
|
|
747 |
// If the item dosen't be selected , its celleditor must be hidden. |
748 |
hideCellEditor(item); |
709 |
item.unhighlight(); |
749 |
item.unhighlight(); |
710 |
iterator.remove(); |
750 |
iterator.remove(); |
711 |
} |
751 |
} |
712 |
} |
752 |
} |
713 |
} |
753 |
} |
714 |
|
754 |
|
|
|
755 |
/** |
756 |
* Hide cellEditor |
757 |
* @param cellEditor |
758 |
*/ |
759 |
private void hideCellEditor(CellEditor cellEditor) { |
760 |
if (cellEditor != null && cellEditor.getControl().isVisible()) { |
761 |
cellEditor.removeListener(cellEditorListener); |
762 |
cellEditor.deactivate(); |
763 |
cellEditor.getControl().setVisible(false); |
764 |
} |
765 |
} |
766 |
|
767 |
/** |
768 |
* Hide cellEditor |
769 |
* @param cellEditor |
770 |
*/ |
771 |
private void hideCellEditor(GraphItem item) { |
772 |
CellEditor cellEditor = item.getCellEditor(); |
773 |
hideCellEditor(cellEditor); |
774 |
} |
775 |
|
715 |
private void fireWidgetSelectedEvent(Item item) { |
776 |
private void fireWidgetSelectedEvent(Item item) { |
716 |
Iterator iterator = selectionListeners.iterator(); |
777 |
Iterator iterator = selectionListeners.iterator(); |
717 |
while (iterator.hasNext()) { |
778 |
while (iterator.hasNext()) { |
Lines 722-728
Link Here
|
722 |
SelectionEvent event = new SelectionEvent(swtEvent); |
783 |
SelectionEvent event = new SelectionEvent(swtEvent); |
723 |
selectionListener.widgetSelected(event); |
784 |
selectionListener.widgetSelected(event); |
724 |
} |
785 |
} |
725 |
|
|
|
726 |
} |
786 |
} |
727 |
|
787 |
|
728 |
/** |
788 |
/** |
Lines 1195-1198
Link Here
|
1195 |
return (GraphItem) figure2ItemMap.get(figure); |
1255 |
return (GraphItem) figure2ItemMap.get(figure); |
1196 |
} |
1256 |
} |
1197 |
|
1257 |
|
|
|
1258 |
private class InnerCellEditorListener implements ICellEditorListener { |
1259 |
|
1260 |
private GraphItem hostItem = null; |
1261 |
|
1262 |
public GraphItem getHostItem() { |
1263 |
return hostItem; |
1264 |
} |
1265 |
|
1266 |
public void setHostItem(GraphItem hostItem) { |
1267 |
this.hostItem = hostItem; |
1268 |
} |
1269 |
|
1270 |
public void applyEditorValue() { |
1271 |
if (hostItem != null) { |
1272 |
ICellEditorManager manager = hostItem.getCellEditorManager(); |
1273 |
CellEditor cellEditor = hostItem.getCellEditor(); |
1274 |
if (manager != null && cellEditor != null) { |
1275 |
manager.commit(cellEditor.getValue(), hostItem); |
1276 |
} |
1277 |
} |
1278 |
} |
1279 |
|
1280 |
public void cancelEditor() { |
1281 |
if (hostItem != null) { |
1282 |
ICellEditorManager manager = hostItem.getCellEditorManager(); |
1283 |
CellEditor cellEditor = hostItem.getCellEditor(); |
1284 |
if (manager != null && cellEditor != null) { |
1285 |
manager.bringDown(); |
1286 |
} |
1287 |
} |
1288 |
} |
1289 |
|
1290 |
public void editorValueChanged(boolean oldValidState, boolean newValidState) { |
1291 |
if (hostItem != null) { |
1292 |
ICellEditorManager manager = hostItem.getCellEditorManager(); |
1293 |
CellEditor cellEditor = hostItem.getCellEditor(); |
1294 |
if (manager != null && cellEditor != null) { |
1295 |
cellEditor.removeListener(this); |
1296 |
manager.locatCellEditor(cellEditor); |
1297 |
cellEditor.addListener(this); |
1298 |
} |
1299 |
} |
1300 |
} |
1301 |
} |
1302 |
|
1198 |
} |
1303 |
} |