use of org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento in project windowbuilder by eclipse.
the class MenuInfo method addClipboardSupport.
private void addClipboardSupport() {
addBroadcastListener(new JavaEventListener() {
@Override
public void clipboardCopy_Argument(JavaInfo javaInfo, ParameterDescription parameter, Expression argument, String[] source) throws Exception {
if (javaInfo == m_this && parameter.getIndex() == 0) {
source[0] = "%parent%";
}
}
@Override
public void clipboardCopy(JavaInfo javaInfo, List<ClipboardCommand> commands) throws Exception {
// copy items
if (javaInfo == m_this) {
for (MenuItemInfo item : getChildrenItems()) {
final JavaInfoMemento itemMemento = JavaInfoMemento.createMemento(item);
commands.add(new ClipboardCommand() {
private static final long serialVersionUID = 0L;
@Override
public void execute(JavaInfo javaInfo) throws Exception {
MenuItemInfo item = (MenuItemInfo) itemMemento.create(javaInfo);
IMenuPolicy policy = MenuObjectInfoUtils.getMenuInfo(javaInfo).getPolicy();
policy.commandCreate(item, null);
itemMemento.apply();
}
});
}
}
}
});
}
use of org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento in project windowbuilder by eclipse.
the class MenuItemInfo method addBroadcastListeners.
// //////////////////////////////////////////////////////////////////////////
//
// Broadcast
//
// //////////////////////////////////////////////////////////////////////////
private void addBroadcastListeners() {
addBroadcastListener(m_stylePropertyListener);
addBroadcastListener(new JavaEventListener() {
@Override
public void addAfter(JavaInfo parent, JavaInfo child) throws Exception {
// add child menu for item creation with SWT.CASCADE style
if (child == m_this) {
if (JavaInfoUtils.hasTrueParameter(m_this, "MenuItem.createCascadeMenu")) {
addSubMenu();
}
removeBroadcastListener(this);
}
}
});
addBroadcastListener(new JavaEventListener() {
@Override
public void clipboardCopy(JavaInfo javaInfo, List<ClipboardCommand> commands) throws Exception {
// copy sub-menu
if (javaInfo == m_this) {
if (hasSubMenu()) {
MenuInfo menuInfo = getChildren(MenuInfo.class).get(0);
final JavaInfoMemento menuMemento = JavaInfoMemento.createMemento(menuInfo);
commands.add(new ClipboardCommand() {
private static final long serialVersionUID = 0L;
@Override
public void execute(JavaInfo javaInfo) throws Exception {
MenuInfo menu = (MenuInfo) menuMemento.create(javaInfo);
menu.command_CREATE((MenuItemInfo) javaInfo);
menuMemento.apply();
}
});
}
}
}
});
}
use of org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento in project windowbuilder by eclipse.
the class JMenuPolicyImpl method commandPaste.
@SuppressWarnings("unchecked")
public List<?> commandPaste(Object mementoObject, final Object nextObject) throws Exception {
List<ComponentInfo> pastedObjects = Lists.newArrayList();
List<JavaInfoMemento> mementos = (List<JavaInfoMemento>) mementoObject;
for (JavaInfoMemento memento : mementos) {
ComponentInfo newComponent = (ComponentInfo) memento.create(m_menu);
commandCreate(newComponent, nextObject);
memento.apply();
pastedObjects.add(newComponent);
}
return pastedObjects;
}
use of org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento in project windowbuilder by eclipse.
the class MenuUtils method copyPasteItems.
/**
* Adds broadcast listener for copy/paste items of menu container.
*
* @param container
* some menu container, {@link JMenuInfo} or {@link JPopupMenuInfo}.
*/
public static void copyPasteItems(final ContainerInfo container) {
container.addBroadcastListener(new JavaEventListener() {
@Override
public void clipboardCopy(JavaInfo javaInfo, List<ClipboardCommand> commands) throws Exception {
if (javaInfo == container) {
for (ComponentInfo item : container.getChildrenComponents()) {
final JavaInfoMemento memento = JavaInfoMemento.createMemento(item);
commands.add(new ClipboardCommand() {
private static final long serialVersionUID = 0L;
@Override
public void execute(JavaInfo javaInfo) throws Exception {
IMenuInfo menuObject;
if (javaInfo instanceof JMenuInfo) {
menuObject = MenuObjectInfoUtils.getMenuInfo(javaInfo);
} else {
menuObject = MenuObjectInfoUtils.getMenuPopupInfo(javaInfo).getMenu();
}
// paste item
ComponentInfo item = (ComponentInfo) memento.create(javaInfo);
menuObject.getPolicy().commandCreate(item, null);
memento.apply();
}
});
}
}
}
});
}
use of org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento in project windowbuilder by eclipse.
the class LayoutPolicyUtils2 method getPasteCommand.
// //////////////////////////////////////////////////////////////////////////
//
// Paste
//
// //////////////////////////////////////////////////////////////////////////
/**
* @return the {@link Command} that performs generic {@link JavaInfo} paste operation.
*/
public static <T extends JavaInfo> Command getPasteCommand(final JavaInfo existingHierarchyObject, final PasteRequest request, final Class<T> componentClass, final IPasteProcessor<T> processor) {
@SuppressWarnings("unchecked") final List<JavaInfoMemento> mementos = (List<JavaInfoMemento>) request.getMemento();
return ExecutionUtils.runObjectLog(new RunnableObjectEx<Command>() {
@Override
public Command runObject() throws Exception {
// prepare models
final List<JavaInfo> components;
{
components = Lists.newArrayList();
for (JavaInfoMemento memento : mementos) {
JavaInfo javaInfo = memento.create(existingHierarchyObject);
if (componentClass.isAssignableFrom(javaInfo.getClass())) {
components.add(javaInfo);
} else {
return null;
}
}
// set objects for selection
request.setObjects(components);
}
// create command
return new EditCommand(existingHierarchyObject) {
@Override
@SuppressWarnings("unchecked")
protected void executeEdit() throws Exception {
for (int i = 0; i < components.size(); i++) {
processor.process((T) components.get(i));
mementos.get(i).apply();
}
}
};
}
}, null);
}
Aggregations