Search in sources :

Example 21 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class DesignerPalette method getVisualCategory.

/**
 * @return the {@link ICategory} for given {@link CategoryInfo}.
 */
private ICategory getVisualCategory(final CategoryInfo categoryInfo) {
    ICategory category = m_categoryInfoToVisual.get(categoryInfo);
    if (category == null) {
        final String categoryId = categoryInfo.getId();
        category = new ICategory() {

            private boolean m_open;

            @Override
            public List<IEntry> getEntries() {
                final List<EntryInfo> entryInfoList = Lists.newArrayList(categoryInfo.getEntries());
                // add new EntryInfo's using broadcast
                ExecutionUtils.runIgnore(new RunnableEx() {

                    @Override
                    public void run() throws Exception {
                        getBroadcastPalette().entries(categoryInfo, entryInfoList);
                    }
                });
                // convert EntryInfo's into IEntry's
                List<IEntry> entries = Lists.newArrayList();
                for (EntryInfo entryInfo : entryInfoList) {
                    if (entryInfo.isVisible()) {
                        IEntry entry = getVisualEntry(entryInfo);
                        if (entry != null) {
                            entries.add(entry);
                        }
                    }
                }
                return entries;
            }

            @Override
            public String getText() {
                return categoryInfo.getName();
            }

            @Override
            public String getToolTipText() {
                return categoryInfo.getDescription();
            }

            @Override
            public boolean isOpen() {
                return m_open;
            }

            @Override
            public void setOpen(boolean open) {
                m_open = open;
                m_openCategories.put(categoryId, open);
            }
        };
        m_categoryInfoToVisual.put(categoryInfo, category);
        m_visualToCategoryInfo.put(category, categoryInfo);
        // set "open" state: from map, or default
        if (m_openCategories.containsKey(categoryId)) {
            category.setOpen(m_openCategories.get(categoryId));
        } else {
            category.setOpen(categoryInfo.isOpen());
        }
    }
    return category;
}
Also used : ICategory(org.eclipse.wb.core.controls.palette.ICategory) IEntry(org.eclipse.wb.core.controls.palette.IEntry) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ComponentEntryInfo(org.eclipse.wb.core.editor.palette.model.entry.ComponentEntryInfo) ToolEntryInfo(org.eclipse.wb.core.editor.palette.model.entry.ToolEntryInfo) InstanceFactoryEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.InstanceFactoryEntryInfo) IDefaultEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.IDefaultEntryInfo) EntryInfo(org.eclipse.wb.core.editor.palette.model.EntryInfo) StaticFactoryEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.StaticFactoryEntryInfo)

Example 22 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class DesignerPalette method showPalette.

/**
 * Shows current {@link PaletteInfo}.
 */
private void showPalette() {
    clearEntryCaches();
    // set IPalette
    IPalette palette = new IPalette() {

        @Override
        public List<ICategory> getCategories() {
            // check for skipping palette during tests
            if (System.getProperty(FLAG_NO_PALETTE) != null) {
                return ImmutableList.of();
            }
            // get categories for palette model
            final List<CategoryInfo> categoryInfoList;
            {
                List<CategoryInfo> pristineCategories = m_manager.getPalette().getCategories();
                categoryInfoList = Lists.newArrayList(pristineCategories);
            }
            // add new CategoryInfo's using broadcast
            ExecutionUtils.runLog(new RunnableEx() {

                @Override
                public void run() throws Exception {
                    getBroadcastPalette().categories(categoryInfoList);
                    getBroadcastPalette().categories2(categoryInfoList);
                }
            });
            // convert CategoryInfo's into ICategory's
            List<ICategory> categories = Lists.newArrayList();
            for (CategoryInfo categoryInfo : categoryInfoList) {
                if (shouldBeDisplayed(categoryInfo)) {
                    ICategory category = getVisualCategory(categoryInfo);
                    categories.add(category);
                }
            }
            return categories;
        }

        @Override
        public void addPopupActions(IMenuManager menuManager, Object target) {
            new DesignerPalettePopupActions(getOperations()).addPopupActions(menuManager, target);
        }

        @Override
        public void selectDefault() {
            m_editPartViewer.getEditDomain().loadDefaultTool();
        }

        @Override
        public void moveCategory(ICategory _category, ICategory _nextCategory) {
            CategoryInfo category = m_visualToCategoryInfo.get(_category);
            CategoryInfo nextCategory = m_visualToCategoryInfo.get(_nextCategory);
            commands_addWrite(new CategoryMoveCommand(category, nextCategory));
        }

        @Override
        public void moveEntry(IEntry _entry, ICategory _targetCategory, IEntry _nextEntry) {
            EntryInfo entry = m_visualToEntryInfo.get(_entry);
            CategoryInfo category = m_visualToCategoryInfo.get(_targetCategory);
            EntryInfo nextEntry = m_visualToEntryInfo.get(_nextEntry);
            commands_addWrite(new EntryMoveCommand(entry, category, nextEntry));
        }
    };
    m_paletteComposite.setPalette(palette);
    configure_EditDomain_DefaultTool();
}
Also used : CategoryInfo(org.eclipse.wb.core.editor.palette.model.CategoryInfo) EntryMoveCommand(org.eclipse.wb.internal.core.editor.palette.command.EntryMoveCommand) ICategory(org.eclipse.wb.core.controls.palette.ICategory) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) IEntry(org.eclipse.wb.core.controls.palette.IEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ComponentEntryInfo(org.eclipse.wb.core.editor.palette.model.entry.ComponentEntryInfo) ToolEntryInfo(org.eclipse.wb.core.editor.palette.model.entry.ToolEntryInfo) InstanceFactoryEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.InstanceFactoryEntryInfo) IDefaultEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.IDefaultEntryInfo) EntryInfo(org.eclipse.wb.core.editor.palette.model.EntryInfo) StaticFactoryEntryInfo(org.eclipse.wb.internal.core.editor.palette.model.entry.StaticFactoryEntryInfo) IMenuManager(org.eclipse.jface.action.IMenuManager) CategoryMoveCommand(org.eclipse.wb.internal.core.editor.palette.command.CategoryMoveCommand) IPalette(org.eclipse.wb.core.controls.palette.IPalette)

Example 23 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class PaletteManager method commandsRead_fromStream0.

private void commandsRead_fromStream0(InputStream inputStream) throws Exception {
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    parser.parse(inputStream, new DefaultHandler() {

        @Override
        public void startElement(String uri, String localName, final String name, final Attributes attributes) {
            ExecutionUtils.runIgnore(new RunnableEx() {

                @Override
                public void run() throws Exception {
                    commandsRead_singleCommand(name, attributes);
                }
            });
        }
    });
}
Also used : Attributes(org.xml.sax.Attributes) SAXParser(javax.xml.parsers.SAXParser) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Example 24 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class DefaultMultiMode method createTabFolder.

// //////////////////////////////////////////////////////////////////////////
// 
// GUI
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Create tab folder for pages.
 */
protected final void createTabFolder(Composite parent) {
    m_folder = new CTabFolder(parent, SWT.BOTTOM);
    TabFolderDecorator.decorate(m_editor, m_folder);
    m_folder.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showPage((IEditorPage) e.item.getData());
        }
    });
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199499
    // Switching tabs by Ctrl+PageUp/PageDown must not be caught on the inner tab set
    m_folder.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            switch(e.detail) {
                case SWT.TRAVERSE_PAGE_NEXT:
                case SWT.TRAVERSE_PAGE_PREVIOUS:
                    final int detail = e.detail;
                    e.doit = true;
                    e.detail = SWT.TRAVERSE_NONE;
                    // 3.6+
                    ExecutionUtils.runIgnore(new RunnableEx() {

                        @Override
                        public void run() throws Exception {
                            Control control = m_folder.getParent();
                            ReflectionUtils.invokeMethod(control, "traverse(int,org.eclipse.swt.widgets.Event)", detail, new Event());
                        }
                    });
            }
        }
    });
}
Also used : Control(org.eclipse.swt.widgets.Control) CTabFolder(org.eclipse.swt.custom.CTabFolder) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IEditorPage(org.eclipse.wb.core.editor.IEditorPage) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 25 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class JavaPropertiesToolBarContributor method addVariableConvertAction.

private void addVariableConvertAction(IToolBarManager manager, List<ObjectInfo> objects) {
    if (objects.size() == 1 && objects.get(0) instanceof JavaInfo) {
        final JavaInfo javaInfo = (JavaInfo) objects.get(0);
        final VariableSupport variableSupport = javaInfo.getVariableSupport();
        // prepare action
        IAction variableConvertAction = new Action() {

            @Override
            public void run() {
                ExecutionUtils.run(javaInfo, new RunnableEx() {

                    @Override
                    public void run() throws Exception {
                        if (variableSupport.canConvertLocalToField()) {
                            variableSupport.convertLocalToField();
                        } else if (variableSupport.canConvertFieldToLocal()) {
                            variableSupport.convertFieldToLocal();
                        }
                    }
                });
            }
        };
        boolean enabled = false;
        // to field
        if (variableSupport.canConvertLocalToField()) {
            variableConvertAction.setImageDescriptor(DesignerPlugin.getImageDescriptor("structure/local_to_field.gif"));
            variableConvertAction.setToolTipText(Messages.ComponentsPropertiesPage_convertLocalToFieldAction);
            enabled = true;
        }
        // to local
        if (!enabled && variableSupport.canConvertFieldToLocal()) {
            variableConvertAction.setImageDescriptor(DesignerPlugin.getImageDescriptor("structure/field_to_local.gif"));
            variableConvertAction.setToolTipText(Messages.ComponentsPropertiesPage_convertFieldToLocalAction);
            enabled = true;
        }
        // append action
        if (enabled) {
            manager.appendToGroup(GROUP_EDIT, variableConvertAction);
        }
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) JavaInfo(org.eclipse.wb.core.model.JavaInfo) VariableSupport(org.eclipse.wb.internal.core.model.variable.VariableSupport) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Aggregations

RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)259 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)57 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)55 GridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo)42 AbstractGridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.AbstractGridBagLayoutInfo)22 ObjectInfo (org.eclipse.wb.core.model.ObjectInfo)14 List (java.util.List)12 Expression (org.eclipse.jdt.core.dom.Expression)11 IAction (org.eclipse.jface.action.IAction)11 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)11 ControlInfo (org.eclipse.wb.internal.swt.model.widgets.ControlInfo)11 FormLayoutInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo)10 JavaInfo (org.eclipse.wb.core.model.JavaInfo)9 IMenuItemInfo (org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)9 GridLayoutInfo (org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo)9 MenuItemInfo (org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo)9 JavaInfoMemento (org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento)8 AstEditor (org.eclipse.wb.internal.core.utils.ast.AstEditor)8 ControlInfo (org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)8 JTextField (javax.swing.JTextField)7