Search in sources :

Example 1 with JavaInfoMemento

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();
                        }
                    });
                }
            }
        }
    });
}
Also used : IMenuPolicy(org.eclipse.wb.internal.core.model.menu.IMenuPolicy) ClipboardCommand(org.eclipse.wb.internal.core.model.clipboard.ClipboardCommand) IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) JavaEventListener(org.eclipse.wb.core.model.broadcast.JavaEventListener) Expression(org.eclipse.jdt.core.dom.Expression) JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) JavaInfo(org.eclipse.wb.core.model.JavaInfo) ParameterDescription(org.eclipse.wb.internal.core.model.description.ParameterDescription)

Example 2 with JavaInfoMemento

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();
                        }
                    });
                }
            }
        }
    });
}
Also used : ClipboardCommand(org.eclipse.wb.internal.core.model.clipboard.ClipboardCommand) IMenuInfo(org.eclipse.wb.internal.core.model.menu.IMenuInfo) JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) JavaInfo(org.eclipse.wb.core.model.JavaInfo) JavaEventListener(org.eclipse.wb.core.model.broadcast.JavaEventListener)

Example 3 with JavaInfoMemento

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;
}
Also used : JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 4 with JavaInfoMemento

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();
                        }
                    });
                }
            }
        }
    });
}
Also used : ClipboardCommand(org.eclipse.wb.internal.core.model.clipboard.ClipboardCommand) JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) JavaInfo(org.eclipse.wb.core.model.JavaInfo) IMenuInfo(org.eclipse.wb.internal.core.model.menu.IMenuInfo) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo) JavaEventListener(org.eclipse.wb.core.model.broadcast.JavaEventListener)

Example 5 with JavaInfoMemento

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);
}
Also used : Command(org.eclipse.wb.gef.core.Command) EditCommand(org.eclipse.wb.core.gef.command.EditCommand) JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) JavaInfo(org.eclipse.wb.core.model.JavaInfo) List(java.util.List) EditCommand(org.eclipse.wb.core.gef.command.EditCommand)

Aggregations

JavaInfoMemento (org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento)63 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)24 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)18 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)15 JavaInfo (org.eclipse.wb.core.model.JavaInfo)13 ControlInfo (org.eclipse.wb.internal.swt.model.widgets.ControlInfo)13 RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)8 List (java.util.List)7 ClipboardCommand (org.eclipse.wb.internal.core.model.clipboard.ClipboardCommand)7 IMenuInfo (org.eclipse.wb.internal.core.model.menu.IMenuInfo)7 FlowLayoutInfo (org.eclipse.wb.internal.swing.model.layout.FlowLayoutInfo)7 MenuInfo (org.eclipse.wb.internal.swt.model.widgets.menu.MenuInfo)7 JavaEventListener (org.eclipse.wb.core.model.broadcast.JavaEventListener)5 Point (org.eclipse.wb.draw2d.geometry.Point)5 IMenuPolicy (org.eclipse.wb.internal.core.model.menu.IMenuPolicy)5 EditPart (org.eclipse.wb.gef.core.EditPart)4 PasteTool (org.eclipse.wb.gef.core.tools.PasteTool)4 IImplicitCreationSupport (org.eclipse.wb.internal.core.model.creation.IImplicitCreationSupport)4 FillLayoutInfo (org.eclipse.wb.internal.swt.model.layout.FillLayoutInfo)4 RowLayoutInfo (org.eclipse.wb.internal.swt.model.layout.RowLayoutInfo)4