Search in sources :

Example 6 with ButtonBar

use of com.extjs.gxt.ui.client.widget.button.ButtonBar in project jahia by Jahia.

the class TranslateContentEngine method init.

protected void init() {
    setLayout(new FitLayout());
    setBodyBorder(false);
    int windowHeight = com.google.gwt.user.client.Window.getClientHeight() - 10;
    int windowWidth = com.google.gwt.user.client.Window.getClientWidth() - 10;
    setSize(windowWidth, windowHeight);
    setClosable(true);
    setResizable(true);
    setModal(true);
    setMaximizable(true);
    setHeadingHtml(Messages.get("label.translate", "Translate") + ": " + node.getName());
    LayoutContainer panel = new LayoutContainer();
    panel.setLayout(new BorderLayout());
    sourceLangPropertiesEditor = new LangPropertiesEditor(node, Arrays.asList(GWTJahiaItemDefinition.CONTENT), false, srcLanguage, null, new LangPropertiesEditor.CallBack() {

        @Override
        public void execute() {
            if (targetLangPropertiesEditor != null && targetLangPropertiesEditor.isNeedRefresh()) {
                // target lang properties editor is waiting for the source lang properties editor to be fully loaded
                // it's now the case, so refresh it.
                targetLangPropertiesEditor.refresh();
            }
        }
    });
    targetLangPropertiesEditor = new LangPropertiesEditor(node, Arrays.asList(GWTJahiaItemDefinition.CONTENT), true, destLanguage, sourceLangPropertiesEditor, new LangPropertiesEditor.CallBack() {

        @Override
        public void execute() {
            wipCheckbox.setValue(workInProgressByLocale.contains(targetLangPropertiesEditor.getDisplayedLocale().getLanguage()));
        }
    });
    // Fill WIP infos
    if (node.getWorkInProgressStatus() != null) {
        // set languages
        if (node.getWorkInProgressLanguages() != null) {
            workInProgressByLocale.addAll(node.getWorkInProgressLanguages());
        }
    }
    Button copyButton = new Button(Messages.get("label.translate.copy", "Copy to other language"));
    copyButton.addStyleName("button-translatecopy");
    sourceLangPropertiesEditor.getTopBar().add(copyButton);
    copyButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            PropertiesEditor sourcePropertiesEditor = sourceLangPropertiesEditor.getPropertiesEditorByLang(sourceLangPropertiesEditor.getDisplayedLocale().getLanguage());
            List<GWTJahiaNodeProperty> props = sourcePropertiesEditor.getProperties();
            Map<String, PropertiesEditor.PropertyAdapterField> fieldsMap = targetLangPropertiesEditor.getPropertiesEditorByLang(targetLangPropertiesEditor.getDisplayedLocale().getLanguage()).getFieldsMap();
            for (final GWTJahiaNodeProperty prop : props) {
                if (sourcePropertiesEditor.getGWTJahiaItemDefinition(prop).isInternationalized()) {
                    final Field<?> f = fieldsMap.get(prop.getName()).getField();
                    FormFieldCreator.copyValue(prop, f);
                }
            }
        }
    });
    panel.add(sourceLangPropertiesEditor, new BorderLayoutData(Style.LayoutRegion.WEST, windowWidth / 2));
    panel.add(targetLangPropertiesEditor, new BorderLayoutData(Style.LayoutRegion.EAST, windowWidth / 2));
    add(panel);
    LayoutContainer buttonsPanel = new LayoutContainer();
    buttonsPanel.setBorders(false);
    buttonBar = new ButtonBar();
    buttonBar.setAlignment(Style.HorizontalAlignment.CENTER);
    initFooter();
    buttonsPanel.add(buttonBar);
    setBottomComponent(buttonsPanel);
    setFooter(true);
    layout();
}
Also used : PropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor) LangPropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.LangPropertiesEditor) ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) LangPropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.LangPropertiesEditor) Field(com.extjs.gxt.ui.client.widget.form.Field) BorderLayout(com.extjs.gxt.ui.client.widget.layout.BorderLayout) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) Button(com.extjs.gxt.ui.client.widget.button.Button) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 7 with ButtonBar

use of com.extjs.gxt.ui.client.widget.button.ButtonBar in project jahia by Jahia.

the class VersioningTabItem method init.

/**
 * Create the tab item
 */
@Override
public void init(final NodeHolder engine, final AsyncTabItem tab, String locale) {
    if (!tab.isProcessed()) {
        this.locale = locale;
        JahiaContentManagementService.App.getInstance().getVersions(engine.getNode().getPath(), new BaseAsyncCallback<List<GWTJahiaNodeVersion>>() {

            public void onSuccess(List<GWTJahiaNodeVersion> result) {
                final ListStore<GWTJahiaNodeVersion> all = new ListStore<GWTJahiaNodeVersion>();
                all.add(result);
                List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
                ColumnConfig column = new ColumnConfig();
                column.setId("label");
                column.setSortable(false);
                column.setHeaderHtml("Name");
                column.setWidth(100);
                column.setRenderer(new GridCellRenderer() {

                    public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
                        GWTJahiaNodeVersion version = (GWTJahiaNodeVersion) model;
                        String value = Messages.get("label.version", "Version") + " ";
                        if (version.getLabel() != null && !"".equals(version.getLabel())) {
                            String[] strings = version.getLabel().split("_at_");
                            if (strings.length == 2) {
                                String date = DateTimeFormat.getMediumDateTimeFormat().format(DateTimeFormat.getFormat("yyyy_MM_dd_HH_mm_ss").parse(strings[1]));
                                for (String versionKey : new String[] { "published", "uploaded" }) {
                                    if (strings[0].contains(versionKey)) {
                                        value = Messages.getWithArgs("label.version." + versionKey, "Compare staging version with the version " + versionKey + " at {0}", new Object[] { date });
                                        break;
                                    }
                                }
                            } else {
                                value = version.getLabel();
                            }
                        }
                        return value;
                    }
                });
                configs.add(column);
                if (PermissionsUtils.isPermitted("jcr:write", engine.getNode()) && !engine.getNode().isLocked()) {
                    column = new ColumnConfig();
                    column.setSortable(false);
                    column.setHeaderHtml("Action");
                    column.setWidth(200);
                    column.setRenderer(new GridCellRenderer() {

                        public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
                            ButtonBar buttonBar = new ButtonBar();
                            Button button = new Button(Messages.get("label.compare.with.staging.engine", "Compare With Staging"));
                            button.addStyleName("button-compare-staging");
                            button.setToolTip(Messages.get("label.compare.with.staging.engine", "Compare With Staging"));
                            final GWTJahiaNodeVersion version = (GWTJahiaNodeVersion) model;
                            button.addSelectionListener(new SelectionListener<ButtonEvent>() {

                                @Override
                                public void componentSelected(ButtonEvent ce) {
                                    // add 30s to the date to be sure to display the right version
                                    new CompareEngine(version.getNode().getUUID(), VersioningTabItem.this.locale, false, version.getNode().getPath(), new Date(version.getDate().getTime() + (30l * 1000l)), engine, version.getWorkspace(), version.getLabel()).show();
                                }
                            });
                            buttonBar.add(button);
                            return buttonBar;
                        }
                    });
                    configs.add(column);
                }
                Grid<GWTJahiaNodeVersion> grid = new Grid<GWTJahiaNodeVersion>(all, new ColumnModel(configs));
                grid.setAutoExpandColumn("label");
                tab.add(grid);
                tab.layout();
                tab.show();
            }
        });
        tab.setProcessed(true);
    }
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) Date(java.util.Date) ListStore(com.extjs.gxt.ui.client.store.ListStore) Button(com.extjs.gxt.ui.client.widget.button.Button) ArrayList(java.util.ArrayList) List(java.util.List) GWTJahiaNodeVersion(org.jahia.ajax.gwt.client.data.node.GWTJahiaNodeVersion) CompareEngine(org.jahia.ajax.gwt.client.widget.content.compare.CompareEngine)

Example 8 with ButtonBar

use of com.extjs.gxt.ui.client.widget.button.ButtonBar in project jahia by Jahia.

the class TrashboardEngine method init.

private void init() {
    setHeadingHtml(Messages.get("label.trashboard", "Trash Board"));
    setLayout(new FitLayout());
    setSize(800, 600);
    setBorders(false);
    setBodyBorder(false);
    setModal(true);
    setMaximizable(true);
    setDraggable(false);
    getHeader().setBorders(false);
    // data proxy
    RpcProxy<PagingLoadResult<GWTJahiaNode>> proxy = new RpcProxy<PagingLoadResult<GWTJahiaNode>>() {

        @Override
        protected void load(Object loadConfig, AsyncCallback<PagingLoadResult<GWTJahiaNode>> callback) {
            JahiaContentManagementService.App.getInstance().searchSQL("select * from [jmix:markedForDeletionRoot] where isdescendantnode(['" + JahiaGWTParameters.getSiteNode().getPath().replace("'", "''") + "'])", -1, 0, null, FIELDS, true, callback);
        }
    };
    // tree loader
    final ListLoader<ListLoadResult<GWTJahiaNode>> loader = new BaseListLoader<ListLoadResult<GWTJahiaNode>>(proxy);
    final ListStore<GWTJahiaNode> deletedNodes = new ListStore<GWTJahiaNode>(loader);
    ArrayList<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("icon", "", 40);
    column.setResizable(false);
    column.setSortable(false);
    column.setMenuDisabled(true);
    column.setAlignment(Style.HorizontalAlignment.CENTER);
    column.setRenderer(NodeColumnConfigList.ICON_RENDERER);
    columns.add(column);
    column = new ColumnConfig("displayName", Messages.get("label.name", "Name"), 100);
    columns.add(column);
    column = new ColumnConfig("j:deletionDate", Messages.get("label.deletionDate", "Deletion date"), 150);
    columns.add(column);
    column = new ColumnConfig("j:deletionUser", Messages.get("label.deletionUser", "User"), 150);
    columns.add(column);
    final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
    column = new ColumnConfig("undelete", Messages.get("label.undelete", "Undelete"), 100);
    column.setRenderer(new GridCellRenderer<GWTJahiaNode>() {

        public Object render(final GWTJahiaNode gwtJahiaNode, String property, ColumnData columnData, int rowIndex, int colIndex, ListStore<GWTJahiaNode> listStore, Grid<GWTJahiaNode> grid) {
            Button button = new Button(Messages.get("label.undelete", "Undelete"), new SelectionListener<ButtonEvent>() {

                @Override
                public void componentSelected(ButtonEvent buttonEvent) {
                    MessageBox.confirm(Messages.get("label.information", "Information"), Messages.getWithArgs("message.undelete.confirm", "Do you really want to undelete the selected resource {0}?", new String[] { ((GWTJahiaNode) gwtJahiaNode).getDisplayName() }), new Listener<MessageBoxEvent>() {

                        public void handleEvent(MessageBoxEvent be) {
                            if (be.getButtonClicked().getItemId().equalsIgnoreCase(Dialog.YES)) {
                                service.undeletePaths(Arrays.asList(gwtJahiaNode.getPath()), new BaseAsyncCallback() {

                                    @Override
                                    public void onApplicationFailure(Throwable throwable) {
                                        Log.error(throwable.getMessage(), throwable);
                                        MessageBox.alert(Messages.get("label.error", "Error"), throwable.getMessage(), null);
                                    }

                                    public void onSuccess(Object result) {
                                        deletedNodes.remove(gwtJahiaNode);
                                    }
                                });
                            }
                        }
                    });
                }
            });
            button.addStyleName("button-undelete");
            button.setIcon(StandardIconsProvider.STANDARD_ICONS.restore());
            return button;
        }
    });
    columns.add(column);
    column = new ColumnConfig("Delete", Messages.get("label.delete", "Delete"), 80);
    column.setRenderer(new GridCellRenderer<GWTJahiaNode>() {

        public Object render(final GWTJahiaNode gwtJahiaNode, String property, ColumnData columnData, int rowIndex, int colIndex, ListStore<GWTJahiaNode> listStore, Grid<GWTJahiaNode> grid) {
            if (gwtJahiaNode.getAggregatedPublicationInfo().getStatus() != GWTJahiaPublicationInfo.NOT_PUBLISHED) {
                return null;
            }
            Button button = new Button(Messages.get("label.delete", "Delete"), new SelectionListener<ButtonEvent>() {

                @Override
                public void componentSelected(ButtonEvent buttonEvent) {
                    MessageBox.confirm(Messages.get("label.warning", "Warning"), Messages.getWithArgs("message.remove.single.confirm", "Do you really want to remove the selected resource {0}?", new String[] { gwtJahiaNode.getDisplayName() }) + Messages.get("message.remove.warning", "<br/><span style=\"font-style:bold;color:red;\">" + "Warning: this will erase the content definitively" + " from the repository.</span>"), new Listener<MessageBoxEvent>() {

                        public void handleEvent(MessageBoxEvent be) {
                            if (be.getButtonClicked().getItemId().equalsIgnoreCase(Dialog.YES)) {
                                service.deletePaths(Arrays.asList(gwtJahiaNode.getPath()), new BaseAsyncCallback<GWTJahiaNode>() {

                                    @Override
                                    public void onApplicationFailure(Throwable throwable) {
                                        Log.error(throwable.getMessage(), throwable);
                                        MessageBox.alert(Messages.get("label.error", "Error"), throwable.getMessage(), null);
                                    }

                                    public void onSuccess(GWTJahiaNode result) {
                                        deletedNodes.remove(gwtJahiaNode);
                                    }
                                });
                            }
                        }
                    });
                }
            });
            button.addStyleName("button-delete");
            button.setIcon(StandardIconsProvider.STANDARD_ICONS.delete());
            return button;
        }
    });
    columns.add(column);
    column = new ColumnConfig("infos", "", 100);
    column.setRenderer(new GridCellRenderer() {

        public Object render(final ModelData modelData, String property, ColumnData columnData, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
            Button button = new Button(Messages.get("label.information", "Information"), new SelectionListener<ButtonEvent>() {

                @Override
                public void componentSelected(ButtonEvent buttonEvent) {
                    PreviewWindow w = new PreviewWindow(linker, (GWTJahiaNode) modelData);
                    w.show();
                }
            });
            button.addStyleName("button-info");
            button.setIcon(StandardIconsProvider.STANDARD_ICONS.information());
            return button;
        }
    });
    columns.add(column);
    ColumnModel cm = new ColumnModel(columns);
    grid = new Grid<GWTJahiaNode>(deletedNodes, cm);
    grid.setAutoExpandColumn("displayName");
    grid.setAutoExpandMax(1000);
    add(grid);
    bar = new ButtonBar();
    bar.setAlignment(Style.HorizontalAlignment.CENTER);
    Button cancel = new Button(Messages.get("label.close", "Close"), new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent event) {
            container.closeEngine();
        }
    });
    cancel.addStyleName("button-close");
    bar.add(cancel);
    loader.load();
}
Also used : ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) ArrayList(java.util.ArrayList) ListStore(com.extjs.gxt.ui.client.store.ListStore) JahiaContentManagementServiceAsync(org.jahia.ajax.gwt.client.service.content.JahiaContentManagementServiceAsync) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) Button(com.extjs.gxt.ui.client.widget.button.Button) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Example 9 with ButtonBar

use of com.extjs.gxt.ui.client.widget.button.ButtonBar in project jahia by Jahia.

the class PublicationManagerEngine method init.

/**
 * init
 */
private void init() {
    setHeadingHtml(Messages.get("label.publicationmanager", "Publication Manager"));
    setLayout(new FitLayout());
    setSize(800, 600);
    setBorders(false);
    setBodyBorder(false);
    setModal(true);
    setMaximizable(true);
    getHeader().setBorders(false);
    getHeader().setIcon(ToolbarIconProvider.getInstance().getIcon("siteRepository"));
    // tree component
    GWTJahiaNodeTreeFactory factory = new GWTJahiaNodeTreeFactory(Arrays.asList("/sites/" + linker.getSelectionContext().getMainNode().getSiteKey()), true);
    factory.setNodeTypes(nodeTypes);
    factory.setFields(Arrays.asList(GWTJahiaNode.NAME, GWTJahiaNode.DISPLAY_NAME, GWTJahiaNode.PUBLICATION_INFOS, GWTJahiaNode.WORKFLOW_INFOS));
    factory.setSelectedPath(linker.getSelectionContext().getMainNode().getPath());
    loader = factory.getLoader();
    List<ColumnConfig> columns = new LinkedList<ColumnConfig>();
    ColumnConfig config = new ColumnConfig("displayName", Messages.get("label.name", "Name"), 150);
    config.setRenderer(NodeColumnConfigList.NAME_TREEGRID_RENDERER);
    config.setSortable(false);
    columns.add(config);
    checkboxMap = new HashMap<String, LayoutContainer>();
    for (GWTJahiaLanguage language : languages) {
        config = new PublicationCheckColumnConfig("publicationInfos", language.getDisplayName(), 100);
        config.setDataIndex(language.getLanguage());
        config.setSortable(false);
        TableData td = new TableData();
        td.setHorizontalAlign(Style.HorizontalAlignment.CENTER);
        td.setVerticalAlign(Style.VerticalAlignment.MIDDLE);
        HorizontalPanel p = new HorizontalPanel();
        // final LayoutContainer ctn = new LayoutContainer();
        // ctn.addStyleName("x-grid3-check-col");
        // ctn.setWidth(16);
        // ctn.setHeight(16);
        // p.add(ctn,td);
        p.add(new Text(language.getDisplayName()), td);
        config.setWidget(p, language.getLanguage());
        // checkboxMap.put(language.getLanguage(), ctn);
        columns.add(config);
    }
    ColumnModel cm = new ColumnModel(columns);
    // cm.addHeaderGroup(0, 1, new HeaderGroupConfig("Publication Info", 1, columns.size() - 1));
    m_tree = factory.getTreeGrid(cm);
    for (ColumnConfig column : columns) {
        if (column instanceof CheckColumnConfig) {
            m_tree.addPlugin((ComponentPlugin) column);
        }
    }
    m_tree.setHideHeaders(false);
    m_tree.setIconProvider(ContentModelIconProvider.getInstance());
    m_tree.setAutoExpand(false);
    m_tree.setAutoExpandMax(1000);
    m_tree.setAutoExpandMin(150);
    m_tree.setAutoExpandColumn("displayName");
    m_tree.setBorders(true);
    setScrollMode(Style.Scroll.AUTO);
    add(m_tree);
    ButtonBar buttonBar = new ButtonBar();
    buttonBar.setAlignment(Style.HorizontalAlignment.CENTER);
    Button button = new Button(Messages.get("label.publish", "Publish"));
    button.addStyleName("button-publish");
    buttonBar.add(button);
    Button cancelButton = new Button(Messages.get("label.cancel", "Cancel"));
    cancelButton.addStyleName("button-cancel");
    buttonBar.add(cancelButton);
    setBottomComponent(buttonBar);
    m_tree.mask(Messages.get("label.loading", "Loading..."), "x-mask-loading");
    loader.addLoadListener(new LoadListener() {

        public void loaderLoad(LoadEvent le) {
            m_tree.unmask();
        }
    });
    loader.load();
    cancelButton.addListener(Events.Select, new Listener<ComponentEvent>() {

        public void handleEvent(ComponentEvent ce) {
            hide();
        }
    });
    button.addSelectionListener(new StartWorkflowButtonSelectionListener(this));
}
Also used : GWTJahiaLanguage(org.jahia.ajax.gwt.client.data.GWTJahiaLanguage) ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) LoadEvent(com.extjs.gxt.ui.client.data.LoadEvent) Button(com.extjs.gxt.ui.client.widget.button.Button) GWTJahiaNodeTreeFactory(org.jahia.ajax.gwt.client.widget.node.GWTJahiaNodeTreeFactory) TableData(com.extjs.gxt.ui.client.widget.layout.TableData) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 10 with ButtonBar

use of com.extjs.gxt.ui.client.widget.button.ButtonBar in project jahia by Jahia.

the class WorkflowHistoryPanel method init.

private void init() {
    setBorders(false);
    removeAll();
    final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
    // data proxy
    RpcProxy<List<GWTJahiaWorkflowHistoryItem>> proxy = new RpcProxy<List<GWTJahiaWorkflowHistoryItem>>() {

        @Override
        protected void load(Object loadConfig, AsyncCallback<List<GWTJahiaWorkflowHistoryItem>> callback) {
            if (loadConfig == null) {
                if (dashboard) {
                    service.getWorkflowHistoryForUser(callback);
                } else {
                    service.getWorkflowHistoryProcesses(nodeId, locale, callback);
                }
            } else if (loadConfig instanceof GWTJahiaWorkflowHistoryProcess) {
                final GWTJahiaWorkflowHistoryProcess process = (GWTJahiaWorkflowHistoryProcess) loadConfig;
                service.getWorkflowHistoryTasks(process.getProvider(), process.getProcessId(), callback);
            } else {
                callback.onSuccess(new ArrayList<GWTJahiaWorkflowHistoryItem>());
            }
        }
    };
    // tree loader
    final TreeLoader<GWTJahiaWorkflowHistoryItem> loader = new BaseTreeLoader<GWTJahiaWorkflowHistoryItem>(proxy) {

        @Override
        public boolean hasChildren(GWTJahiaWorkflowHistoryItem parent) {
            return parent instanceof GWTJahiaWorkflowHistoryProcess;
        }
    };
    // trees store
    final TreeStore<GWTJahiaWorkflowHistoryItem> store = new TreeStore<GWTJahiaWorkflowHistoryItem>(loader);
    store.setStoreSorter(new StoreSorter<GWTJahiaWorkflowHistoryItem>() {

        @Override
        public int compare(Store<GWTJahiaWorkflowHistoryItem> store, GWTJahiaWorkflowHistoryItem m1, GWTJahiaWorkflowHistoryItem m2, String property) {
            return m1.getStartDate().compareTo(m2.getStartDate());
        }
    });
    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("displayName", Messages.get("label.name", "Name"), 400);
    column.setRenderer(new WidgetTreeGridCellRenderer<GWTJahiaWorkflowHistoryItem>() {

        @Override
        public Widget getWidget(GWTJahiaWorkflowHistoryItem historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemListStore, Grid<GWTJahiaWorkflowHistoryItem> grid) {
            if (dashboard && historyItem instanceof GWTJahiaWorkflowHistoryTask) {
                final GWTJahiaWorkflowHistoryProcess parent = (GWTJahiaWorkflowHistoryProcess) ((TreeGrid<GWTJahiaWorkflowHistoryItem>) grid).getTreeStore().getParent(historyItem);
                for (final GWTJahiaWorkflowTask task : parent.getAvailableTasks()) {
                    if (task.getId().equals(historyItem.getId())) {
                        Button b = new Button(historyItem.<String>get("displayName"));
                        b.addStyleName("button-details");
                        b.addSelectionListener(new SelectionListener<ButtonEvent>() {

                            @Override
                            public void componentSelected(ButtonEvent ce) {
                                EngineWindow container = new EngineWindow();
                                container.setClosable(false);
                                container.setMaximizable(false);
                                container.setMinimizable(false);
                                container.addStyleName("workflow-dashboard-publication-window");
                                container.setId("workflow-dashboard-publication-window");
                                // get path from the publication info, not used for unpublished
                                CustomWorkflow customWorkflowInfo = parent.getRunningWorkflow().getCustomWorkflowInfo();
                                String path = "";
                                if (customWorkflowInfo instanceof PublicationWorkflow && ((PublicationWorkflow) customWorkflowInfo).getPublicationInfos().size() > 0) {
                                    path = ((PublicationWorkflow) customWorkflowInfo).getPublicationInfos().get(0).getMainPath();
                                }
                                new WorkflowActionDialog(path, parent.getRunningWorkflow(), task, linker, customWorkflowInfo, container);
                                container.showEngine();
                                final RootPanel rootPanel = RootPanel.get("workflowComponent");
                                final ContentPanel rootPanelWidget = (ContentPanel) rootPanel.getWidget(0);
                                // rootPanelWidget.hide();
                                container.addListener(Events.Hide, new Listener<BaseEvent>() {

                                    @Override
                                    public void handleEvent(BaseEvent be) {
                                        rootPanelWidget.show();
                                        init();
                                        layout(true);
                                    }
                                });
                                rootPanel.add(container.getPanel());
                            }
                        });
                        return b;
                    }
                }
            }
            return new Label(historyItem.<String>get("displayName"));
        }
    });
    config.add(column);
    column = new ColumnConfig("locale", 80);
    column.setRenderer(new GridCellRenderer<ModelData>() {

        @Override
        public Object render(ModelData historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
            if (dashboard && historyItem.get("workflow") instanceof GWTJahiaWorkflow) {
                String lang = ((GWTJahiaWorkflow) historyItem.get("workflow")).get("locale");
                if (lang != null && JahiaGWTParameters.getLanguage(lang) != null) {
                    return "<img src=\"" + JahiaGWTParameters.getLanguage(lang).getImage() + "\"/>&nbsp;";
                }
            }
            return "";
        }
    });
    config.add(column);
    column = new ColumnConfig("user", Messages.get("label.user", "User"), 140);
    config.add(column);
    column = new ColumnConfig("nodeWrapper", Messages.get("label.workflow.start.node", "Workflow Starting Node"), 400);
    column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {

        /**
         * Returns the HTML to be used in a grid cell.
         *
         * @param model    the model
         * @param property the model property
         * @param config   the column config
         * @param rowIndex the row index
         * @param colIndex the cell index
         * @param store    the data store
         * @param grid     the grid
         * @return the cell HTML or Component instance
         */
        @Override
        public Object render(GWTJahiaWorkflowHistoryItem model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> store, Grid<GWTJahiaWorkflowHistoryItem> grid) {
            final GWTJahiaNode wrapper = (GWTJahiaNode) model.getProperties().get("nodeWrapper");
            if (wrapper != null) {
                return new Label(wrapper.getDisplayName() + " (" + wrapper.getPath() + ")");
            }
            List<GWTJahiaWorkflowHistoryItem> models = store.getModels();
            for (final GWTJahiaWorkflowHistoryItem historyItem : models) {
                final GWTJahiaNode nodewrapper = (GWTJahiaNode) historyItem.getProperties().get("nodeWrapper");
                if (nodewrapper != null && historyItem.getProcessId().equals(model.getProcessId()) && historyItem instanceof GWTJahiaWorkflowHistoryProcess) {
                    ButtonBar buttonBar = new ButtonBar();
                    Button previewButton = new Button(Messages.get("label.preview"));
                    previewButton.addStyleName("button-preview");
                    previewButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

                        @Override
                        public void componentSelected(ButtonEvent ce) {
                            String path = nodewrapper.getPath();
                            String locale = nodewrapper.getLanguageCode();
                            JahiaContentManagementService.App.getInstance().getNodeURL("render", path, null, null, "default", locale, false, new BaseAsyncCallback<String>() {

                                @Override
                                public void onSuccess(String url) {
                                    Window window = new Window();
                                    window.addStyleName("content-preview");
                                    window.setMaximizable(true);
                                    window.setSize(800, 600);
                                    window.setUrl(url);
                                    // window.setPosition(engine.getPosition(true).x + 50, engine.getPosition(true).y + 50);
                                    window.show();
                                }
                            });
                        }
                    });
                    buttonBar.add(previewButton);
                    Button inContextButton = new Button(Messages.get("label.preview.context"));
                    inContextButton.addStyleName("button-incontext-preview");
                    inContextButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

                        @Override
                        public void componentSelected(ButtonEvent ce) {
                            String path = nodewrapper.getPath();
                            String locale = JahiaGWTParameters.getLanguage();
                            JahiaContentManagementService.App.getInstance().getNodeURL("render", path, null, null, "default", locale, true, new BaseAsyncCallback<String>() {

                                @Override
                                public void onSuccess(String url) {
                                    Window window = new Window();
                                    window.addStyleName("content-incontext-preview");
                                    window.setMaximizable(true);
                                    window.setSize(1000, 750);
                                    window.setUrl(url);
                                    // window.setPosition(engine.getPosition(true).x + 50, engine.getPosition(true).y + 50);
                                    window.show();
                                }
                            });
                        }
                    });
                    buttonBar.add(inContextButton);
                    return buttonBar;
                }
            }
            return new Label("");
        }
    });
    config.add(column);
    column = new ColumnConfig("startDate", Messages.get("org.jahia.engines.processDisplay.tab.startdate", "Start date"), 150);
    column.setDateTimeFormat(Formatter.DEFAULT_DATETIME_FORMAT);
    config.add(column);
    column = new ColumnConfig("endDate", Messages.get("org.jahia.engines.processDisplay.tab.enddate", "End date"), 150);
    column.setDateTimeFormat(Formatter.DEFAULT_DATETIME_FORMAT);
    config.add(column);
    column = new ColumnConfig("duration", Messages.get("org.jahia.engines.processDisplay.column.duration", "Duration"), 80);
    column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {

        @Override
        public Object render(GWTJahiaWorkflowHistoryItem historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> store, Grid<GWTJahiaWorkflowHistoryItem> grid) {
            Long duration = historyItem.getDuration();
            String display = "-";
            if (duration != null) {
                long time = duration.longValue();
                if (time < 1000) {
                    display = time + " " + Messages.get("label.milliseconds", "ms");
                } else if (time < 1000 * 60L) {
                    display = ((long) (time / 1000)) + " " + Messages.get("label.seconds", "sec");
                } else if (time < 1000 * 60 * 60L) {
                    display = ((long) (time / (1000 * 60L))) + " " + Messages.get("label.minutes", "min") + " " + ((long) ((time % (1000 * 60L)) / 1000)) + " " + Messages.get("label.seconds", "sec");
                } else {
                    display = ((long) (time / (1000 * 60 * 60L))) + " " + Messages.get("label_hours", "h") + " " + ((long) ((time % (1000 * 60 * 60L)) / (1000 * 60L))) + " " + Messages.get("label.minutes", "min");
                }
            }
            return new Label(display);
        }
    });
    config.add(column);
    if (PermissionsUtils.isPermitted("viewWorkflowTab", JahiaGWTParameters.getSiteNode().getPermissions())) {
        column = new ColumnConfig("operation", Messages.get("label.operation", "Operation"), 150);
        column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {

            @Override
            public Object render(final GWTJahiaWorkflowHistoryItem model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemListStore, Grid<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemGrid) {
                if (model instanceof GWTJahiaWorkflowHistoryProcess && !((GWTJahiaWorkflowHistoryProcess) model).isFinished()) {
                    Button button = new Button(Messages.get("label.abort", "Abort"));
                    button.addStyleName("button-abort");
                    button.addSelectionListener(new SelectionListener<ButtonEvent>() {

                        @Override
                        public void componentSelected(ButtonEvent ce) {
                            JahiaContentManagementService.App.getInstance().abortWorkflow(model.getId(), model.getProvider(), new BaseAsyncCallback<String>() {

                                @Override
                                public void onSuccess(String url) {
                                    store.removeAll();
                                    loader.load();
                                }
                            });
                        }
                    });
                    button.setIcon(StandardIconsProvider.STANDARD_ICONS.delete());
                    return button;
                }
                return new Label("");
            }
        });
        config.add(column);
    }
    ColumnModel cm = new ColumnModel(config);
    final TreeGrid<GWTJahiaWorkflowHistoryItem> tree = new TreeGrid<GWTJahiaWorkflowHistoryItem>(store, cm);
    tree.setStateful(true);
    tree.setBorders(true);
    tree.getStyle().setNodeOpenIcon(StandardIconsProvider.STANDARD_ICONS.workflow());
    tree.getStyle().setNodeCloseIcon(StandardIconsProvider.STANDARD_ICONS.workflow());
    tree.getStyle().setLeafIcon(StandardIconsProvider.STANDARD_ICONS.workflowTask());
    tree.setAutoExpandColumn("displayName");
    tree.getTreeView().setRowHeight(25);
    tree.setTrackMouseOver(false);
    tree.setAutoExpandMax(1000);
    add(tree);
    listener = new Poller.PollListener<TaskEvent>() {

        @Override
        public void handlePollingResult(TaskEvent result) {
            if (result.getEndedTask() != null) {
                for (GWTJahiaWorkflowHistoryItem item : new ArrayList<GWTJahiaWorkflowHistoryItem>(store.getAllItems())) {
                    if (item instanceof GWTJahiaWorkflowHistoryProcess) {
                        for (GWTJahiaWorkflowTask task : new ArrayList<GWTJahiaWorkflowTask>(item.getAvailableTasks())) {
                            if (task.getId().equals(result.getEndedTask())) {
                                item.getAvailableTasks().remove(task);
                            }
                        }
                        if (item.getAvailableTasks().isEmpty()) {
                            store.remove(item);
                        }
                    } else if (item instanceof GWTJahiaWorkflowHistoryTask && item.getId().equals(result.getEndedTask())) {
                        store.remove(item);
                    }
                }
            }
        }
    };
    Poller.getInstance().registerListener(listener, TaskEvent.class);
    if (engine != null) {
        engine.addListener(Events.Hide, new Listener<BaseEvent>() {

            @Override
            public void handleEvent(BaseEvent be) {
                if (listener != null) {
                    Poller.getInstance().unregisterListener(listener, TaskEvent.class);
                }
            }
        });
    }
}
Also used : GWTJahiaWorkflowHistoryProcess(org.jahia.ajax.gwt.client.data.workflow.history.GWTJahiaWorkflowHistoryProcess) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) ArrayList(java.util.ArrayList) Widget(com.google.gwt.user.client.ui.Widget) Label(com.extjs.gxt.ui.client.widget.Label) GWTJahiaWorkflowHistoryTask(org.jahia.ajax.gwt.client.data.workflow.history.GWTJahiaWorkflowHistoryTask) PublicationWorkflow(org.jahia.ajax.gwt.client.widget.publication.PublicationWorkflow) WorkflowActionDialog(org.jahia.ajax.gwt.client.widget.workflow.WorkflowActionDialog) Button(com.extjs.gxt.ui.client.widget.button.Button) ArrayList(java.util.ArrayList) List(java.util.List) Poller(org.jahia.ajax.gwt.client.widget.poller.Poller) GWTJahiaWorkflow(org.jahia.ajax.gwt.client.data.workflow.GWTJahiaWorkflow) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) BaseTreeLoader(com.extjs.gxt.ui.client.data.BaseTreeLoader) GWTJahiaWorkflowHistoryItem(org.jahia.ajax.gwt.client.data.workflow.history.GWTJahiaWorkflowHistoryItem) TaskEvent(org.jahia.ajax.gwt.client.widget.poller.TaskEvent) CustomWorkflow(org.jahia.ajax.gwt.client.widget.workflow.CustomWorkflow) ModelData(com.extjs.gxt.ui.client.data.ModelData) ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) RootPanel(com.google.gwt.user.client.ui.RootPanel) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) JahiaContentManagementServiceAsync(org.jahia.ajax.gwt.client.service.content.JahiaContentManagementServiceAsync) TreeGrid(com.extjs.gxt.ui.client.widget.treegrid.TreeGrid) Window(com.extjs.gxt.ui.client.widget.Window) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) GWTJahiaWorkflowTask(org.jahia.ajax.gwt.client.data.workflow.GWTJahiaWorkflowTask)

Aggregations

ButtonBar (com.extjs.gxt.ui.client.widget.button.ButtonBar)13 Button (com.extjs.gxt.ui.client.widget.button.Button)10 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)6 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)5 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Window (com.extjs.gxt.ui.client.widget.Window)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)3 ModelData (com.extjs.gxt.ui.client.data.ModelData)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)2 Label (com.extjs.gxt.ui.client.widget.Label)2 BaseAsyncCallback (org.jahia.ajax.gwt.client.core.BaseAsyncCallback)2 JahiaContentManagementServiceAsync (org.jahia.ajax.gwt.client.service.content.JahiaContentManagementServiceAsync)2 BaseTreeLoader (com.extjs.gxt.ui.client.data.BaseTreeLoader)1 LoadEvent (com.extjs.gxt.ui.client.data.LoadEvent)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1