use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method createUngroupElementsAction.
private IListenerAction createUngroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
if (elt instanceof FrameElementGroup) {
selectedGroups.add((FrameElementGroup) elt);
} else {
selectedGroups.addAll(elt.getRootElement().getEltGroups());
}
}
if (selectedGroups.size() > 0) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, editSequence);
removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
}
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {
@Override
public String getPresentationName() {
return UNGROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, null);
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
regroup(group);
}
}
};
editSequence.addEdit(edit);
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method removeRootElement.
private void removeRootElement(final String presentationName, final FrameElement rootElt, final FrameElementGroup fromGrp, IUndoableEditSequence editSequence) {
Set<FrameElementGroup> rootEltGrps = rootElt.getEltGroups();
int numGrps = rootEltGrps.size();
if (numGrps > 0) {
final List<FrameElementGroup> deleteGrps = new ArrayList<FrameElementGroup>(rootEltGrps);
final int[] atIndexes = new int[numGrps];
Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
int i = 0;
while (eltGrps.hasNext()) {
FrameElementGroup grp = eltGrps.next();
atIndexes[i++] = grp.indexOf(rootElt);
if (grp != fromGrp) {
grp.remove(rootElt);
if (grp.size() == 1) {
ungroup(grp, editSequence);
removeRootElement(presentationName, grp, fromGrp, editSequence);
}
}
}
if (editSequence != null) {
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Delete, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
while (eltGrps.hasNext()) {
FrameElementGroup grp = eltGrps.next();
if (grp != fromGrp) {
grp.remove(rootElt);
if (grp.size() == 1) {
ungroup(grp, null);
}
}
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
int i = 0;
while (eltGrps.hasNext()) {
FrameElementGroup grp = eltGrps.next();
if (grp.size() == 1) {
regroup(grp);
}
grp.add(atIndexes[i++], rootElt);
}
}
};
editSequence.addEdit(edit);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class DesignEditorCmd method pasteFrameElementGroup.
private static int pasteFrameElementGroup(FrameElementGroup eltGroup, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSeq, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
int numPasted = 0;
makeEltGroupNameUnique(eltGroup, frame);
groups.add(eltGroup);
groups.addAll(eltGroup.getEltGroups());
checkForRemoteLabel(eltGroup, addedRemoteLabels);
Iterator<FrameElement> elementsToAdd = eltGroup.iterator();
while (elementsToAdd.hasNext()) {
FrameElement eltToAdd = elementsToAdd.next();
if (eltToAdd instanceof IWidget) {
numPasted += pasteWidget((IWidget) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
} else if (eltToAdd instanceof SimpleWidgetGroup) {
numPasted += pasteWidgetGroup((SimpleWidgetGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
} else if (eltToAdd instanceof FrameElementGroup) {
numPasted += pasteFrameElementGroup((FrameElementGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
}
}
return numPasted;
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class DesignEditorCmd method pasteElements.
// pasteFrameElementGroup
public static int pasteElements(Design design, final Frame frame, Collection<Object> objects, DemoStateManager mgr, IUndoableEditSequence editSequence) {
// If given objects contain widgets, insert into the given frame
if ((objects != null) && (objects.size() > 0)) {
Iterator<Object> objIt = objects.iterator();
Set<SimpleWidgetGroup> addedGroups = new HashSet<SimpleWidgetGroup>();
final Set<IWidget> addedRemoteLabels = new HashSet<IWidget>();
final Set<FrameElementGroup> addedEltGroups = new HashSet<FrameElementGroup>();
int numPasted = 0;
// May need to add a device
int currentDeviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
// create them.
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof IWidget) {
IWidget widget = (IWidget) o;
numPasted += pasteWidget(widget, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
SimpleWidgetGroup group = widget.getParentGroup();
if (group != null) {
addedGroups.add(group);
}
} else if (o instanceof FrameElementGroup) {
numPasted += pasteFrameElementGroup((FrameElementGroup) o, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
}
}
Iterator<SimpleWidgetGroup> groupsIter = addedGroups.iterator();
while (groupsIter.hasNext()) {
SimpleWidgetGroup group = groupsIter.next();
repositionChildren(group);
if (group instanceof GridButtonGroup) {
((GridButtonGroup) group).recalculateOffsets();
}
addedEltGroups.addAll(group.getEltGroups());
}
Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
while (eltGroups.hasNext()) {
frame.addEltGroup(eltGroups.next());
}
Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
while (remoteLabels.hasNext()) {
IWidget remoteLabel = remoteLabels.next();
if (!frame.containsWidget(remoteLabel)) {
String uniqueName = NamedObjectUtil.makeNameUnique(remoteLabel.getName(), frame.getWidgets());
remoteLabel.setName(uniqueName);
frame.addWidget(remoteLabel);
}
}
IUndoableEdit edit = new AUndoableEdit(CogToolLID.Paste) {
@Override
public String getPresentationName() {
return PASTE;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
while (eltGroups.hasNext()) {
frame.addEltGroup(eltGroups.next());
}
Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
while (remoteLabels.hasNext()) {
IWidget remoteLabel = remoteLabels.next();
if (!frame.containsWidget(remoteLabel)) {
frame.addWidget(remoteLabel);
}
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
while (eltGroups.hasNext()) {
frame.removeEltGroup(eltGroups.next());
}
Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
while (remoteLabels.hasNext()) {
IWidget remoteLabel = remoteLabels.next();
if (frame.containsWidget(remoteLabel)) {
frame.removeWidget(remoteLabel);
}
}
}
};
editSequence.addEdit(edit);
return numPasted;
}
return 0;
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorInteraction method confirmDeleteElements.
/**
* Delete confirmation method.
*/
public boolean confirmDeleteElements(FrameElement[] elements) {
String msg = "";
// Choose the message plural or singular.
if (elements.length > 1) {
msg = CONFIRM_DELETE_WIDGETS_MSG;
} else {
msg = CONFIRM_DELETE_ONE_WIDGET_MSG;
}
String[] eltNames = new String[elements.length];
for (int i = 0; i < elements.length; i++) {
FrameElement elt = elements[i];
eltNames[i] = elt.getName();
if ((elt instanceof FrameElementGroup) && ((eltNames[i] == null) || eltNames[i].equals(""))) {
eltNames[i] = UNNAMED_WIDGET_GROUP_LABEL;
}
}
return (SWT.OK == WindowUtil.presentConfirmItemsDialog(window, CONFIRM_TITLE, msg, eltNames));
}
Aggregations