Search in sources :

Example 11 with Window

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

the class CustomizedPreviewActionItem method onComponentSelection.

@Override
public void onComponentSelection() {
    final Window window = new Window();
    window.addStyleName("customized-preview");
    window.setSize(500, 430);
    window.setPlain(true);
    window.setModal(true);
    window.setBlinkModal(true);
    window.setBorders(false);
    window.setHeadingHtml(Messages.get("label.preview.window.title", "Customized preview"));
    window.setLayout(new FitLayout());
    window.setButtonAlign(Style.HorizontalAlignment.CENTER);
    window.setBodyBorder(false);
    // data proxy
    RpcProxy<PagingLoadResult<GWTJahiaNode>> proxy = new RpcProxy<PagingLoadResult<GWTJahiaNode>>() {

        @Override
        protected void load(Object pageLoaderConfig, AsyncCallback<PagingLoadResult<GWTJahiaNode>> callback) {
            if (userSearchField != null) {
                String newSearch = userSearchField.getText().trim().replace("'", "''");
                String query = "select * from [jnt:user] as u where (isdescendantnode(u,'/users/') or isdescendantnode(u,'/sites/" + JahiaGWTParameters.getSiteKey().replace("'", "''") + "/users/'))";
                if (newSearch.length() > 0) {
                    query += " and (CONTAINS(u.*,'*" + newSearch + "*') OR LOWER(u.[j:nodename]) LIKE '*" + newSearch.toLowerCase() + "*') ";
                }
                query += " ORDER BY u.[j:nodename]";
                // reset offset to 0 if the search value has changed
                int offset = lastUserSearchValue != null && lastUserSearchValue.equals(newSearch) ? ((PagingLoadConfig) pageLoaderConfig).getOffset() : 0;
                final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
                service.searchSQL(query, ((PagingLoadConfig) pageLoaderConfig).getLimit(), offset, null, GWTJahiaNode.DEFAULT_USER_FIELDS, false, callback);
                // remember last searched value
                lastUserSearchValue = newSearch;
            }
        }
    };
    final BasePagingLoader<PagingLoadResult<GWTJahiaNode>> loader = new BasePagingLoader<PagingLoadResult<GWTJahiaNode>>(proxy);
    userSearchField = new SearchField(Messages.get("label.search", "Search: "), false) {

        @Override
        public void onFieldValidation(String value) {
            loader.load();
        }

        @Override
        public void onSaveButtonClicked(String value) {
        }
    };
    userSearchField.setWidth(490);
    loader.setLimit(10);
    loader.load();
    HorizontalPanel panel = new HorizontalPanel();
    panel.add(userSearchField);
    ListStore<GWTJahiaNode> store = new ListStore<GWTJahiaNode>(loader);
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    columns.add(new ColumnConfig("displayName", Messages.get("label.username", "User name"), 150));
    columns.add(new ColumnConfig("j:lastName", Messages.get("label.lastName", "Last name"), 130));
    columns.add(new ColumnConfig("j:firstName", Messages.get("label.firstName", "First name"), 130));
    // columns.add(new ColumnConfig("siteName", "Site name", 80));
    columns.add(new ColumnConfig("providerKey", Messages.get("column.provider.label", "Provider"), 75));
    // columns.add(new ColumnConfig("email", "Email", 100));
    ColumnModel cm = new ColumnModel(columns);
    final PagingToolBar toolBar = new PagingToolBar(10);
    toolBar.bind(loader);
    toolBar.setBorders(false);
    toolBar.setWidth(480);
    userGrid = new Grid<GWTJahiaNode>(store, cm);
    userGrid.getSelectionModel().setSelectionMode(Style.SelectionMode.SINGLE);
    userGrid.setLoadMask(true);
    userGrid.setBorders(false);
    userGrid.setHeight(250);
    userGrid.setWidth(490);
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(userGrid);
    verticalPanel.add(toolBar);
    window.setTopComponent(panel);
    panel = new HorizontalPanel();
    panel.setTableHeight("30px");
    panel.setVerticalAlign(Style.VerticalAlignment.BOTTOM);
    Label label = new Label("&nbsp;&nbsp;&nbsp;&nbsp;" + Messages.get("label.preview.window.date", "Pick a date for the preview") + "&nbsp;&nbsp;&nbsp;");
    label.setWidth(200);
    label.setLabelFor("previewDate");
    final Date date = new Date();
    final CalendarField calendarField = new CalendarField("yyyy-MM-dd HH:mm", true, false, "previewDate", false, date);
    panel.add(label);
    panel.add(calendarField);
    verticalPanel.add(panel);
    window.add(verticalPanel);
    // Channel selector
    panel = new HorizontalPanel();
    panel.setTableHeight("30px");
    panel.setVerticalAlign(Style.VerticalAlignment.BOTTOM);
    label = new Label("&nbsp;&nbsp;&nbsp;&nbsp;" + Messages.get("label.preview.window.channel", "Channel") + "&nbsp;&nbsp;&nbsp;");
    label.setLabelFor("previewChannel");
    // we will setup the right elements now because we will need to reference them in the event listener
    final Label orientationLabel = new Label("&nbsp;&nbsp;&nbsp;&nbsp;" + Messages.get("label.preview.window.channelOrientation", "Orientation") + "&nbsp;&nbsp;&nbsp;");
    orientationLabel.setLabelFor("previewChannelOrientation");
    orientationLabel.hide();
    final ListStore<GWTJahiaBasicDataBean> orientations = new ListStore<GWTJahiaBasicDataBean>();
    final ComboBox<GWTJahiaBasicDataBean> orientationCombo = new ComboBox<GWTJahiaBasicDataBean>();
    orientationCombo.setDisplayField("displayName");
    orientationCombo.setName("previewChannelOrientation");
    orientationCombo.setStore(orientations);
    orientationCombo.setTypeAhead(true);
    orientationCombo.setTriggerAction(TriggerAction.ALL);
    orientationCombo.hide();
    // now we can setup the channel selection combo box
    final ListStore<GWTJahiaChannel> states = new ListStore<GWTJahiaChannel>();
    final ComboBox<GWTJahiaChannel> combo = new ComboBox<GWTJahiaChannel>();
    JahiaContentManagementServiceAsync contentService = JahiaContentManagementService.App.getInstance();
    contentService.getChannels(new BaseAsyncCallback<List<GWTJahiaChannel>>() {

        public void onSuccess(List<GWTJahiaChannel> result) {
            states.add(result);
            combo.setStore(states);
        }
    });
    combo.setDisplayField("display");
    combo.setName("previewChannel");
    combo.setStore(states);
    combo.setTypeAhead(true);
    combo.setTriggerAction(TriggerAction.ALL);
    combo.addSelectionChangedListener(new SelectionChangedListener<GWTJahiaChannel>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GWTJahiaChannel> event) {
            GWTJahiaChannel selectedChannel = event.getSelectedItem();
            Map<String, String> capabilities = selectedChannel.getCapabilities();
            if (capabilities != null && capabilities.containsKey("variants")) {
                String[] variants = capabilities.get("variants").split(",");
                String[] displayNames = null;
                if (capabilities.containsKey("variants-displayNames")) {
                    displayNames = capabilities.get("variants-displayNames").split(",");
                }
                ListStore<GWTJahiaBasicDataBean> orientations = orientationCombo.getStore();
                orientations.removeAll();
                for (int i = 0; i < variants.length; i++) {
                    String displayName = (displayNames == null ? variants[i] : displayNames[i]);
                    orientations.add(new GWTJahiaBasicDataBean(variants[i], displayName));
                }
                orientationCombo.setValue(orientations.getAt(0));
                orientationLabel.show();
                orientationCombo.show();
            } else {
                orientationLabel.hide();
                orientationCombo.hide();
            }
        }
    });
    panel.add(label);
    panel.add(combo);
    panel.add(orientationLabel);
    panel.add(orientationCombo);
    verticalPanel.add(panel);
    window.add(verticalPanel);
    Button ok = new Button(Messages.get("label.preview.window.confirm", "Show customized preview"));
    ok.addStyleName("button-preview");
    ok.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent buttonEvent) {
            final GWTJahiaNode node = linker.getSelectionContext().getMainNode();
            if (node != null) {
                String path = node.getPath();
                String locale = JahiaGWTParameters.getLanguage();
                JahiaContentManagementService.App.getInstance().getNodeURL(null, path, null, null, "default", locale, false, new BaseAsyncCallback<String>() {

                    @Override
                    public void onSuccess(String url) {
                        GWTJahiaNode selectedItem = userGrid.getSelectionModel().getSelectedItem();
                        String alias = null;
                        List<String> urlParameters = new ArrayList<String>();
                        if (selectedItem != null) {
                            alias = "alias=" + selectedItem.getName();
                            urlParameters.add(alias);
                        }
                        String previewDate = null;
                        if (calendarField.getValue().after(date)) {
                            previewDate = "prevdate=" + calendarField.getValue().getTime();
                            urlParameters.add(previewDate);
                        }
                        GWTJahiaChannel channel = combo.getValue();
                        String windowFeatures = null;
                        if ((channel != null) && (!"default".equals(channel.getValue()))) {
                            urlParameters.add("channel=" + channel.getValue());
                            Map<String, String> capabilities = channel.getCapabilities();
                            if (capabilities != null && capabilities.containsKey("variants")) {
                                int variantIndex = 0;
                                String[] variants = capabilities.get("variants").split(",");
                                String variant = orientationCombo.getValue().getValue();
                                urlParameters.add("variant=" + variant);
                                for (int i = 0; i < variants.length; i++) {
                                    if (variants[i].equals(variant)) {
                                        variantIndex = i;
                                        break;
                                    }
                                }
                                int[] imageSize = channel.getVariantDecoratorImageSize(variantIndex);
                                windowFeatures = "resizable=no,status=no,menubar=no,toolbar=no,width=" + imageSize[0] + ",height=" + imageSize[1];
                            }
                        }
                        StringBuilder urlParams = new StringBuilder();
                        for (int i = 0; i < urlParameters.size(); i++) {
                            if (i == 0) {
                                urlParams.append("?");
                            }
                            urlParams.append(urlParameters.get(i));
                            if (i < urlParameters.size() - 1) {
                                urlParams.append("&");
                            }
                        }
                        String url1 = url + urlParams.toString();
                        openWindow(url1, "customizedpreview", windowFeatures != null ? windowFeatures : defaultWindowOptions);
                    }
                });
            }
        }
    });
    window.setBottomComponent(ok);
    window.show();
}
Also used : CalendarField(org.jahia.ajax.gwt.client.widget.form.CalendarField) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) ArrayList(java.util.ArrayList) Label(com.extjs.gxt.ui.client.widget.Label) ListStore(com.extjs.gxt.ui.client.store.ListStore) Button(com.extjs.gxt.ui.client.widget.button.Button) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) ArrayList(java.util.ArrayList) List(java.util.List) PagingToolBar(com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar) ComboBox(com.extjs.gxt.ui.client.widget.form.ComboBox) Map(java.util.Map) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) JahiaContentManagementServiceAsync(org.jahia.ajax.gwt.client.service.content.JahiaContentManagementServiceAsync) HorizontalPanel(com.extjs.gxt.ui.client.widget.HorizontalPanel) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) Window(com.extjs.gxt.ui.client.widget.Window) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) GWTJahiaBasicDataBean(org.jahia.ajax.gwt.client.data.GWTJahiaBasicDataBean) BasePagingLoader(com.extjs.gxt.ui.client.data.BasePagingLoader) GWTJahiaChannel(org.jahia.ajax.gwt.client.data.GWTJahiaChannel) Date(java.util.Date) SearchField(org.jahia.ajax.gwt.client.widget.SearchField) VerticalPanel(com.extjs.gxt.ui.client.widget.VerticalPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 12 with Window

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

the class OpenHTMLWindowActionItem method onComponentSelection.

@Override
public void onComponentSelection() {
    Map<String, GWTJahiaProperty> preferences = getGwtToolbarItem().getProperties();
    final GWTJahiaProperty htmlProperty = preferences.get(Constants.HTML);
    if (htmlProperty != null && htmlProperty.getValue() != null) {
        Window window = new Window();
        window.addStyleName("open-html-modal");
        if (getGwtToolbarItem().getTitle() != null) {
            String title = getGwtToolbarItem().getTitle().replaceAll(" ", "_");
            window.setTitle(title);
        }
        window.addText(htmlProperty.getValue());
        window.setModal(true);
        window.setResizable(true);
        window.setClosable(true);
        window.show();
    }
}
Also used : Window(com.extjs.gxt.ui.client.widget.Window) GWTJahiaProperty(org.jahia.ajax.gwt.client.data.GWTJahiaProperty)

Example 13 with Window

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

the class ReleaseModuleWindow method onRender.

@Override
protected void onRender(Element element, int index) {
    super.onRender(element, index);
    String versionInfo = JahiaGWTParameters.getSiteNode().get("j:versionInfo");
    setLayout(new FitLayout());
    setHeadingHtml(Messages.get("label.releaseWar") + "&nbsp;" + versionInfo + "&nbsp;->&nbsp;" + versionInfo.replace("-SNAPSHOT", ""));
    setModal(true);
    setWidth(500);
    setHeight(150);
    final List<Integer> versionNumbers = JahiaGWTParameters.getSiteNode().get("j:versionNumbers");
    final FormPanel formPanel = new FormPanel();
    formPanel.setHeaderVisible(false);
    formPanel.setLabelWidth(150);
    formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    final SimpleComboBox<String> cbNextVersion = new SimpleComboBox<String>();
    cbNextVersion.setFieldLabel(Messages.get("label.nextVersion", "Next iteration version"));
    cbNextVersion.setTriggerAction(ComboBox.TriggerAction.ALL);
    cbNextVersion.setForceSelection(false);
    String minorVersion = generateVersionNumber(versionNumbers, 1);
    cbNextVersion.add(minorVersion);
    cbNextVersion.add(generateVersionNumber(versionNumbers, 0));
    cbNextVersion.setSimpleValue(minorVersion);
    formPanel.add(cbNextVersion);
    final FieldSet fs = new FieldSet();
    fs.setCheckboxToggle(true);
    final FormLayout fl = new FormLayout();
    fl.setLabelWidth(100);
    fl.setDefaultWidth(330);
    fs.setLayout(fl);
    final TextField<String> tfUsername = new TextField<String>();
    final TextField<String> tfPassword = new TextField<String>();
    tfUsername.setFieldLabel(Messages.get("label.username", "Username"));
    tfPassword.setFieldLabel(Messages.get("label.password", "Password"));
    tfPassword.setPassword(true);
    setHeight(300);
    if (releaseInfo.getForgeUrl() != null) {
        fs.setHeadingHtml(Messages.get("label.releaseModule.publishToModuleForge", "Publish to module Private App Store"));
        LabelField lbCatalogUrl = new LabelField();
        lbCatalogUrl.setToolTip(releaseInfo.getForgeUrl());
        lbCatalogUrl.setValue(releaseInfo.getForgeUrl());
        lbCatalogUrl.setFieldLabel(Messages.get("label.url", "URL") + ":");
        fs.add(lbCatalogUrl);
        tfUsername.setValue(ForgeLoginWindow.username);
        tfPassword.setValue(ForgeLoginWindow.password);
        formPanel.add(fs);
    } else if (releaseInfo.getRepositoryUrl() != null) {
        fs.setHeadingHtml(Messages.get("label.releaseModule.publishToMaven", "Publish to Maven distribution server"));
        if (releaseInfo.getRepositoryId() != null) {
            LabelField lbRepoId = new LabelField();
            lbRepoId.setValue(releaseInfo.getRepositoryId());
            lbRepoId.setFieldLabel(Messages.get("label.id", "ID") + ":");
            fs.add(lbRepoId);
        }
        LabelField lbRepoUrl = new LabelField();
        lbRepoUrl.setToolTip(releaseInfo.getRepositoryUrl());
        lbRepoUrl.setValue(releaseInfo.getRepositoryUrl());
        lbRepoUrl.setFieldLabel(Messages.get("label.url", "URL") + ":");
        fs.add(lbRepoUrl);
        formPanel.add(fs);
    }
    fs.add(tfUsername);
    fs.add(tfPassword);
    Button b = new Button(Messages.get("label.release", "Release"), new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent event) {
            String v = cbNextVersion.getRawValue();
            if (v == null || v.length() == 0 || !v.endsWith("-SNAPSHOT")) {
                cbNextVersion.markInvalid(Messages.get("label.snapshotRequired", "Working version number must end with -SNAPSHOT"));
                return;
            }
            releaseInfo.setNextVersion(cbNextVersion.getRawValue());
            releaseInfo.setPublishToForge(releaseInfo.getForgeUrl() != null && fs.isVisible() && fs.isExpanded());
            releaseInfo.setPublishToMaven(releaseInfo.getRepositoryUrl() != null && fs.isVisible() && fs.isExpanded());
            releaseInfo.setUsername(tfUsername.getValue());
            releaseInfo.setPassword(tfPassword.getValue());
            if (releaseInfo.isPublishToForge()) {
                ForgeLoginWindow.username = tfUsername.getValue();
                ForgeLoginWindow.password = tfPassword.getValue();
            }
            callback.handle(releaseInfo);
        }
    });
    b.addStyleName("button-release");
    formPanel.addButton(b);
    final Window w = this;
    b = new Button(Messages.get("label.cancel", "Cancel"), new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent event) {
            w.hide();
        }
    });
    b.addStyleName("button-cancel");
    formPanel.addButton(b);
    add(formPanel);
}
Also used : FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) Window(com.extjs.gxt.ui.client.widget.Window) SimpleComboBox(com.extjs.gxt.ui.client.widget.form.SimpleComboBox) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) TextField(com.extjs.gxt.ui.client.widget.form.TextField) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Example 14 with Window

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

the class SaveAsReferencesMenuActionItem method onComponentSelection.

@Override
public void onComponentSelection() {
    JahiaContentManagementService.App.getInstance().getPortalNodes(targetName.getValue(), new BaseAsyncCallback<List<GWTJahiaNode>>() {

        @Override
        public void onSuccess(List<GWTJahiaNode> result) {
            if (result == null || result.size() == 0) {
                MessageBox.alert(Messages.get("label.saveAsPortalComponent"), Messages.get("label.saveAsPortalComponent.portalComponents.nonedeclared", "There is no Portal Components folder declared. The component can not be saved"), null);
            } else if (result.size() == 1) {
                saveInPortalNode(result.get(0));
            } else {
                final Window popup = new Window();
                popup.addStyleName("save-as-reference-modal");
                popup.setHeadingHtml(Messages.get("label.saveAsPortalComponent.portalComponents.select", "Select a Portal Components folder"));
                popup.setWidth(500);
                popup.setAutoHeight(true);
                popup.setModal(true);
                FormPanel f = new FormPanel();
                f.setHeaderVisible(false);
                final ComboBox<GWTJahiaNode> portalNodesCombo = new ComboBox<GWTJahiaNode>();
                portalNodesCombo.setStore(new ListStore<GWTJahiaNode>());
                portalNodesCombo.setDisplayField(GWTJahiaNode.PATH);
                portalNodesCombo.setTriggerAction(ComboBox.TriggerAction.ALL);
                portalNodesCombo.setForceSelection(true);
                portalNodesCombo.getStore().add(result);
                ContentPanel p = new ContentPanel();
                p.setLayout(new FitLayout());
                p.setCollapsible(false);
                p.setFrame(false);
                p.setAnimCollapse(false);
                p.setBorders(false);
                p.setBodyBorder(false);
                p.setHeaderVisible(false);
                p.add(portalNodesCombo);
                f.add(p);
                Button b = new Button(Messages.get("label.save", "Save"));
                f.addButton(b);
                b.addSelectionListener(new SelectionListener<ButtonEvent>() {

                    @Override
                    public void componentSelected(ButtonEvent buttonEvent) {
                        GWTJahiaNode portalNode = portalNodesCombo.getValue();
                        if (portalNode != null) {
                            saveInPortalNode(portalNode);
                        }
                        popup.hide();
                    }
                });
                b.addStyleName("button-save");
                Button c = new Button(Messages.get("label.cancel", "Cancel"));
                c.addSelectionListener(new SelectionListener<ButtonEvent>() {

                    @Override
                    public void componentSelected(ButtonEvent buttonEvent) {
                        popup.hide();
                    }
                });
                c.addStyleName("button-cancel");
                f.addButton(c);
                f.setButtonAlign(Style.HorizontalAlignment.CENTER);
                FormButtonBinding binding = new FormButtonBinding(f);
                binding.addButton(b);
                popup.add(f);
                popup.show();
            }
        }

        @Override
        public void onApplicationFailure(Throwable caught) {
            Info.display(Messages.get("label.saveAsPortalComponent"), Messages.get("label.saveAsPortalComponent.cannotGetPortalNodes"));
        }
    });
}
Also used : Window(com.extjs.gxt.ui.client.widget.Window) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) ComboBox(com.extjs.gxt.ui.client.widget.form.ComboBox) FormButtonBinding(com.extjs.gxt.ui.client.widget.form.FormButtonBinding) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) List(java.util.List) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 15 with Window

use of com.extjs.gxt.ui.client.widget.Window 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

Window (com.extjs.gxt.ui.client.widget.Window)19 Button (com.extjs.gxt.ui.client.widget.button.Button)14 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)12 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)11 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)9 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)7 List (java.util.List)6 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)5 ArrayList (java.util.ArrayList)5 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)4 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)4 Label (com.extjs.gxt.ui.client.widget.Label)4 VerticalPanel (com.extjs.gxt.ui.client.widget.VerticalPanel)4 BaseAsyncCallback (org.jahia.ajax.gwt.client.core.BaseAsyncCallback)4 ListStore (com.extjs.gxt.ui.client.store.ListStore)3 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)3 ButtonBar (com.extjs.gxt.ui.client.widget.button.ButtonBar)3 FormButtonBinding (com.extjs.gxt.ui.client.widget.form.FormButtonBinding)3 TextField (com.extjs.gxt.ui.client.widget.form.TextField)3 CenterLayout (com.extjs.gxt.ui.client.widget.layout.CenterLayout)3