Search in sources :

Example 1 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project pentaho-platform by pentaho.

the class SchedulesPanel method createUI.

private void createUI(boolean isAdmin, final boolean isScheduler) {
    table.getElement().setId("schedule-table");
    table.setStylePrimaryName("pentaho-table");
    table.setWidth("100%", true);
    // BISERVER-9331 Column sort indicators should be to the right of header text in the Manage Schedules table.
    if (table.getHeaderBuilder() instanceof AbstractHeaderOrFooterBuilder) {
        ((AbstractHeaderOrFooterBuilder<JsJob>) table.getHeaderBuilder()).setSortIconStartOfLine(false);
    }
    final MultiSelectionModel<JsJob> selectionModel = new MultiSelectionModel<JsJob>(new ProvidesKey<JsJob>() {

        public Object getKey(JsJob item) {
            return item.getJobId();
        }
    });
    table.setSelectionModel(selectionModel);
    Label noDataLabel = new Label(Messages.getString("noSchedules"));
    noDataLabel.setStyleName("noDataForScheduleTable");
    table.setEmptyTableWidget(noDataLabel);
    TextColumn<JsJob> idColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            return job.getJobId();
        }
    };
    idColumn.setSortable(true);
    TextColumn<JsJob> nameColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            return job.getJobName();
        }
    };
    nameColumn.setSortable(true);
    HtmlColumn<JsJob> resourceColumn = new HtmlColumn<JsJob>() {

        @Override
        public String getStringValue(JsJob job) {
            String name = job.getFullResourceName().split("\\.")[0];
            return name.replaceAll("/", "/<wbr/>");
        }
    };
    resourceColumn.setSortable(true);
    HtmlColumn<JsJob> outputPathColumn = new HtmlColumn<JsJob>(new ClickableSafeHtmlCell()) {

        @Override
        public String getStringValue(JsJob jsJob) {
            try {
                String outputPath = jsJob.getOutputPath();
                if (StringUtils.isEmpty(outputPath)) {
                    return "-";
                } else {
                    outputPath = new SafeHtmlBuilder().appendEscaped(outputPath).toSafeHtml().asString();
                    return MessageFormat.format("<span class=''workspace-resource-link'' title=''{0}''>{0}</span>", outputPath);
                }
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    outputPathColumn.setFieldUpdater(new FieldUpdater<JsJob, SafeHtml>() {

        @Override
        public void update(final int index, final JsJob jsJob, final SafeHtml value) {
            if (!value.equals("-")) {
                final Command errorCallback = new Command() {

                    @Override
                    public void execute() {
                        showValidateOutputLocationError();
                    }
                };
                final Command successCallback = new Command() {

                    @Override
                    public void execute() {
                        openOutputLocation(jsJob.getOutputPath());
                    }
                };
                OutputLocationUtils.validateOutputLocation(jsJob.getOutputPath(), successCallback, errorCallback);
            }
        }
    });
    outputPathColumn.setSortable(true);
    TextColumn<JsJob> scheduleColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                return job.getJobTrigger().getDescription();
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    scheduleColumn.setSortable(true);
    TextColumn<JsJob> userNameColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                return job.getUserName();
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    userNameColumn.setSortable(true);
    TextColumn<JsJob> stateColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                // BISERVER-9965
                final String jobState = "COMPLETE".equalsIgnoreCase(job.getState()) ? "FINISHED" : job.getState();
                // not css text-transform because tooltip will use pure text from the cell
                return jobState.substring(0, 1).toUpperCase() + jobState.substring(1).toLowerCase();
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    stateColumn.setSortable(true);
    TextColumn<JsJob> nextFireColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                Date date = job.getNextRun();
                if (date == null) {
                    return "-";
                }
                DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM);
                return format.format(date);
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    nextFireColumn.setSortable(true);
    TextColumn<JsJob> lastFireColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                Date date = job.getLastRun();
                if (date == null) {
                    return "-";
                }
                DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM);
                return format.format(date);
            } catch (Throwable t) {
                return "-";
            }
        }
    };
    lastFireColumn.setSortable(true);
    // table.addColumn(idColumn, "ID");
    table.addColumn(nameColumn, Messages.getString("scheduleName"));
    table.addColumn(scheduleColumn, Messages.getString("recurrence"));
    table.addColumn(resourceColumn, Messages.getString("sourceFile"));
    table.addColumn(outputPathColumn, Messages.getString("outputPath"));
    table.addColumn(lastFireColumn, Messages.getString("lastFire"));
    table.addColumn(nextFireColumn, Messages.getString("nextFire"));
    if (isAdmin) {
        table.addColumn(userNameColumn, Messages.getString("user"));
    }
    table.addColumn(stateColumn, Messages.getString("state"));
    table.addColumnStyleName(0, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(1, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(2, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(3, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(4, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(5, "backgroundContentHeaderTableCell");
    if (isAdmin) {
        table.addColumnStyleName(6, "backgroundContentHeaderTableCell");
    }
    table.addColumnStyleName(isAdmin ? 7 : 6, "backgroundContentHeaderTableCell");
    table.setColumnWidth(nameColumn, 160, Unit.PX);
    table.setColumnWidth(resourceColumn, 200, Unit.PX);
    table.setColumnWidth(outputPathColumn, 180, Unit.PX);
    table.setColumnWidth(scheduleColumn, 170, Unit.PX);
    table.setColumnWidth(lastFireColumn, 120, Unit.PX);
    table.setColumnWidth(nextFireColumn, 120, Unit.PX);
    if (isAdmin) {
        table.setColumnWidth(userNameColumn, 100, Unit.PX);
    }
    table.setColumnWidth(stateColumn, 90, Unit.PX);
    dataProvider.addDataDisplay(table);
    List<JsJob> list = dataProvider.getList();
    ListHandler<JsJob> columnSortHandler = new ListHandler<JsJob>(list);
    columnSortHandler.setComparator(idColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getJobId().compareTo(o2.getJobId()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(nameColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getJobName().compareTo(o2.getJobName()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(resourceColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                String r1 = o1.getShortResourceName();
                String r2 = null;
                if (o2 != null) {
                    r2 = o2.getShortResourceName();
                }
                return (o2 != null) ? r1.compareTo(r2) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(outputPathColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                String r1 = o1.getOutputPath();
                String r2 = null;
                if (o2 != null) {
                    r2 = o2.getOutputPath();
                }
                return (o2 != null) ? r1.compareTo(r2) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(scheduleColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            String s1 = o1.getJobTrigger().getDescription();
            String s2 = o2.getJobTrigger().getDescription();
            return s1.compareTo(s2);
        }
    });
    columnSortHandler.setComparator(userNameColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getUserName().compareTo(o2.getUserName()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(stateColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getState().compareTo(o2.getState()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(nextFireColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 == null || o1.getNextRun() == null) {
                return -1;
            }
            if (o2 == null || o2.getNextRun() == null) {
                return 1;
            }
            if (o1.getNextRun() == o2.getNextRun()) {
                return 0;
            }
            return o1.getNextRun().compareTo(o2.getNextRun());
        }
    });
    columnSortHandler.setComparator(lastFireColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 == null || o1.getLastRun() == null) {
                return -1;
            }
            if (o2 == null || o2.getLastRun() == null) {
                return 1;
            }
            if (o1.getLastRun() == o2.getLastRun()) {
                return 0;
            }
            return o1.getLastRun().compareTo(o2.getLastRun());
        }
    });
    table.addColumnSortHandler(columnSortHandler);
    table.getColumnSortList().push(idColumn);
    table.getColumnSortList().push(resourceColumn);
    table.getColumnSortList().push(outputPathColumn);
    table.getColumnSortList().push(nameColumn);
    table.getSelectionModel().addSelectionChangeHandler(new Handler() {

        public void onSelectionChange(SelectionChangeEvent event) {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (selectedJobs != null && selectedJobs.size() > 0) {
                JsJob[] jobs = selectedJobs.toArray(new JsJob[selectedJobs.size()]);
                editButton.setEnabled(isScheduler);
                if ("NORMAL".equalsIgnoreCase(jobs[0].getState())) {
                    controlScheduleButton.setImage(ImageUtil.getThemeableImage("icon-small", "icon-stop"));
                } else {
                    controlScheduleButton.setImage(ImageUtil.getThemeableImage("icon-small", "icon-run"));
                }
                controlScheduleButton.setEnabled(isScheduler);
                boolean isRunning = "NORMAL".equalsIgnoreCase(jobs[0].getState());
                controlScheduleButton.setToolTip(isRunning ? Messages.getString("stop") : Messages.getString("start"));
                scheduleRemoveButton.setEnabled(isScheduler);
                triggerNowButton.setEnabled(isScheduler);
            } else {
                editButton.setEnabled(false);
                controlScheduleButton.setEnabled(false);
                scheduleRemoveButton.setEnabled(false);
                triggerNowButton.setEnabled(false);
            }
        }
    });
    // BISERVER-9965
    table.addCellPreviewHandler(new CellPreviewEvent.Handler<JsJob>() {

        @Override
        public void onCellPreview(CellPreviewEvent<JsJob> event) {
            if ("mouseover".equals(event.getNativeEvent().getType())) {
                final TableCellElement cell = table.getRowElement(event.getIndex()).getCells().getItem(event.getColumn());
                cell.setTitle(cell.getInnerText());
            }
        }
    });
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true) {

        @Override
        public void setPageStart(int index) {
            if (getDisplay() != null) {
                Range range = getDisplay().getVisibleRange();
                int pageSize = range.getLength();
                // Removed the min to show fixed ranges
                // if (isRangeLimited && display.isRowCountExact()) {
                // index = Math.min(index, display.getRowCount() - pageSize);
                // }
                index = Math.max(0, index);
                if (index != range.getStart()) {
                    getDisplay().setVisibleRange(index, pageSize);
                }
            }
        }
    };
    pager.setDisplay(table);
    // pager.setRangeLimited(false);
    VerticalPanel tableAndPager = new VerticalPanel();
    tableAndPager.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    Toolbar bar = new Toolbar();
    bar.addSpacer(10);
    bar.add(Toolbar.GLUE);
    // Add control scheduler button
    if (isAdmin) {
        final ToolbarButton controlSchedulerButton = new ToolbarButton(ImageUtil.getThemeableImage("icon-small", "icon-start-scheduler"));
        controlSchedulerButton.setCommand(new Command() {

            public void execute() {
                toggleSchedulerOnOff(controlSchedulerButton, isScheduler);
            }
        });
        updateControlSchedulerButtonState(controlSchedulerButton, isScheduler);
        bar.add(controlSchedulerButton);
        bar.addSpacer(20);
    }
    // Add filter button
    filterButton.setCommand(new Command() {

        public void execute() {
            if (filterDialog == null) {
                filterDialog = new FilterDialog(allJobs, filterDialogCallback);
            } else {
                filterDialog.initUI(allJobs);
            }
            filterDialog.center();
        }
    });
    filterButton.setToolTip(Messages.getString("filterSchedules"));
    if (isAdmin) {
        bar.add(filterButton);
    }
    // Add remove filters button
    filterRemoveButton.setCommand(new Command() {

        public void execute() {
            filterDialog = null;
            filters.clear();
            filterAndShowData();
            filterRemoveButton.setEnabled(false);
            filterButton.setImage(ImageUtil.getThemeableImage("icon-small", "icon-filter-add"));
        }
    });
    filterRemoveButton.setToolTip(Messages.getString("removeFilters"));
    filterRemoveButton.setEnabled(filters.size() > 0);
    if (isAdmin) {
        bar.add(filterRemoveButton);
    }
    // Add refresh button
    ToolbarButton refresh = new ToolbarButton(ImageUtil.getThemeableImage("icon-small", "icon-refresh"));
    refresh.setToolTip(Messages.getString("refreshTooltip"));
    refresh.setCommand(new Command() {

        public void execute() {
            RefreshSchedulesCommand cmd = new RefreshSchedulesCommand();
            cmd.execute();
        }
    });
    bar.add(refresh);
    bar.addSpacer(20);
    // Add execute now button
    triggerNowButton.setToolTip(Messages.getString("executeNow"));
    triggerNowButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (selectedJobs != null && selectedJobs.size() > 0) {
                MessageDialogBox messageDialog = new MessageDialogBox(Messages.getString("executeNow"), Messages.getString("executeNowStarted"), false, true, true);
                messageDialog.setCallback(new IDialogCallback() {

                    public void okPressed() {
                        // wait a little to refresh to give schedule time to update the last run
                        Timer t = new Timer() {

                            public void run() {
                                refresh();
                            }
                        };
                        t.schedule(2000);
                    }

                    public void cancelPressed() {
                    }
                });
                messageDialog.center();
                controlJobs(selectedJobs, "triggerNow", RequestBuilder.POST, false);
            }
        }
    });
    triggerNowButton.setEnabled(false);
    bar.add(triggerNowButton);
    // Add control schedule button
    controlScheduleButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (selectedJobs != null && selectedJobs.size() > 0) {
                JsJob[] jobs = selectedJobs.toArray(new JsJob[selectedJobs.size()]);
                if ("NORMAL".equals(jobs[0].getState())) {
                    controlJobs(selectedJobs, "pauseJob", RequestBuilder.POST, false);
                } else {
                    controlJobs(selectedJobs, "resumeJob", RequestBuilder.POST, false);
                }
            }
        }
    });
    controlScheduleButton.setEnabled(false);
    bar.add(controlScheduleButton);
    bar.addSpacer(20);
    // Add edit button
    editButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (selectedJobs != null && selectedJobs.size() > 0) {
                JsJob[] jobs = selectedJobs.toArray(new JsJob[selectedJobs.size()]);
                final JsJob editJob = jobs[0];
                final String url = GWT.getHostPageBaseURL() + "api/repo/files/" + SolutionBrowserPanel.pathToId(editJob.getFullResourceName()) + "/canAccess?cb=" + System.currentTimeMillis() + "&permissions=" + READ_PERMISSION;
                RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
                try {
                    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                    executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

                        public void onError(Request request, Throwable exception) {
                            promptForScheduleResourceError(editJob);
                        }

                        public void onResponseReceived(Request request, Response response) {
                            if ("true".equalsIgnoreCase(response.getText())) {
                                editJob(editJob);
                            } else {
                                promptForScheduleResourceError(editJob);
                            }
                        }
                    });
                } catch (RequestException e) {
                // showError(e);
                }
            }
        }
    });
    editButton.setEnabled(false);
    editButton.setToolTip(Messages.getString("editTooltip"));
    bar.add(editButton);
    // Add remove button
    scheduleRemoveButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (selectedJobs != null && selectedJobs.size() > 0) {
                final PromptDialogBox prompt = new PromptDialogBox(Messages.getString("warning"), Messages.getString("yes"), Messages.getString("no"), false, true);
                prompt.setContent(new Label(Messages.getString("deleteConfirmSchedles", "" + selectedJobs.size())));
                prompt.setCallback(new IDialogCallback() {

                    public void okPressed() {
                        controlJobs(getSelectedJobs(), "removeJob", RequestBuilder.DELETE, true);
                        prompt.hide();
                    }

                    public void cancelPressed() {
                        prompt.hide();
                    }
                });
                prompt.center();
            }
        }
    });
    scheduleRemoveButton.setToolTip(Messages.getString("remove"));
    scheduleRemoveButton.setEnabled(false);
    bar.add(scheduleRemoveButton);
    tableAndPager.add(bar);
    tableAndPager.add(table);
    tableAndPager.add(pager);
    // Add it to the root panel.
    setWidget(tableAndPager);
}
Also used : RefreshSchedulesCommand(org.pentaho.mantle.client.commands.RefreshSchedulesCommand) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Label(com.google.gwt.user.client.ui.Label) JSONString(com.google.gwt.json.client.JSONString) ToolbarButton(org.pentaho.gwt.widgets.client.toolbar.ToolbarButton) AbstractHeaderOrFooterBuilder(com.google.gwt.user.cellview.client.AbstractHeaderOrFooterBuilder) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Toolbar(org.pentaho.gwt.widgets.client.toolbar.Toolbar) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Handler(com.google.gwt.view.client.SelectionChangeEvent.Handler) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Range(com.google.gwt.view.client.Range) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) JSONObject(com.google.gwt.json.client.JSONObject) TableCellElement(com.google.gwt.dom.client.TableCellElement) Set(java.util.Set) HashSet(java.util.HashSet) RequestBuilder(com.google.gwt.http.client.RequestBuilder) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) RequestException(com.google.gwt.http.client.RequestException) HtmlColumn(org.pentaho.mantle.client.ui.column.HtmlColumn) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Request(com.google.gwt.http.client.Request) SimplePager(com.google.gwt.user.cellview.client.SimplePager) Date(java.util.Date) CellPreviewEvent(com.google.gwt.view.client.CellPreviewEvent) Response(com.google.gwt.http.client.Response) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Timer(com.google.gwt.user.client.Timer) RequestCallback(com.google.gwt.http.client.RequestCallback) Command(com.google.gwt.user.client.Command) RefreshSchedulesCommand(org.pentaho.mantle.client.commands.RefreshSchedulesCommand) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat)

Example 2 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetCompleteCandidates method getEmptyTable.

/**
 * Returns the empty table widget
 *
 * @return table widget
 */
public CellTable<MemberCandidate> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<MemberCandidate>(list);
    // Cell table
    table = new PerunTable<MemberCandidate>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<MemberCandidate> columnSortHandler = new ListHandler<MemberCandidate>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // Table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<MemberCandidate>createCheckboxManager());
    // Set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // checkbox column column
    Column<MemberCandidate, MemberCandidate> checkBoxColumn = new Column<MemberCandidate, MemberCandidate>(new PerunCheckboxCell<MemberCandidate>(true, false, (groupId == 0))) {

        @Override
        public MemberCandidate getValue(MemberCandidate object) {
            // Get the value from the selection model.
            GeneralObject go = object.cast();
            go.setChecked(selectionModel.isSelected(object));
            return go.cast();
        }
    };
    // updates the columns size
    table.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    table.addColumn(checkBoxColumn);
    // is member
    TextColumn<MemberCandidate> memberColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            if (groupId == 0) {
                if (candidate.getMember() != null)
                    return "Member of VO";
            } else {
                if (candidate.getMember() != null && candidate.getMember().getSourceGroupId() != 0 && "DIRECT".equalsIgnoreCase(candidate.getMember().getMembershipType()))
                    return "Member of Group";
                if (candidate.getMember() != null && candidate.getMember().getSourceGroupId() != 0 && "INDIRECT".equalsIgnoreCase(candidate.getMember().getMembershipType()))
                    return "Indirect member of Group";
                if (candidate.getMember() != null)
                    return "Member of VO";
            }
            return "";
        }
    };
    // Status column
    final Column<MemberCandidate, String> statusColumn = new Column<MemberCandidate, String>(new PerunStatusCell()) {

        @Override
        public String getValue(MemberCandidate object) {
            if (object.getMember() != null) {
                return object.getMember().getStatus();
            } else {
                return null;
            }
        }
    };
    // Full Name Column
    TextColumn<MemberCandidate> fullNameColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            return getFullNameColumnValue(candidate);
        }
    };
    // E-mail column
    TextColumn<MemberCandidate> emailColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            return getEmailColumnValue(candidate);
        }
    };
    // Login Column
    TextColumn<MemberCandidate> loginColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            return getLoginFromExtSourceOrAllLogins(candidate);
        }
    };
    // Ext Source Column
    TextColumn<MemberCandidate> extSourceColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            return getExtSourceNameOrOrganizationColumn(candidate);
        }
    };
    // already Column
    TextColumn<MemberCandidate> alreadyInPerunColumn = new TextColumn<MemberCandidate>() {

        @Override
        public String getValue(MemberCandidate candidate) {
            if (candidate.getRichUser() != null) {
                return "Local";
            } else {
                return "External identity";
            }
        }
    };
    alreadyInPerunColumn.setSortable(true);
    columnSortHandler.setComparator(alreadyInPerunColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            String o1Val = "External identity";
            String o2Val = "External identity";
            if (o1.getRichUser() != null) {
                o1Val = "Local";
            }
            if (o2.getRichUser() != null) {
                o2Val = "Local";
            }
            return o1Val.compareTo(o2Val);
        }
    });
    memberColumn.setSortable(true);
    columnSortHandler.setComparator(memberColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            String o1Val = "1";
            String o2Val = "1";
            if (o1.getMember() != null)
                o1Val = "0";
            if (o2.getMember() != null)
                o2Val = "0";
            o1Val += getFullNameColumnValue(o1);
            o2Val += getFullNameColumnValue(o2);
            return o1Val.compareTo(o2Val);
        }
    });
    loginColumn.setSortable(true);
    columnSortHandler.setComparator(loginColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            return getLoginFromExtSourceOrAllLogins(o1).compareToIgnoreCase(getLoginFromExtSourceOrAllLogins(o2));
        }
    });
    fullNameColumn.setSortable(true);
    columnSortHandler.setComparator(fullNameColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            return getFullNameColumnValue(o1).compareToIgnoreCase(getFullNameColumnValue(o2));
        }
    });
    extSourceColumn.setSortable(true);
    columnSortHandler.setComparator(extSourceColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            return getExtSourceNameOrOrganizationColumn(o1).compareToIgnoreCase(getExtSourceNameOrOrganizationColumn(o2));
        }
    });
    emailColumn.setSortable(true);
    columnSortHandler.setComparator(emailColumn, new Comparator<MemberCandidate>() {

        public int compare(MemberCandidate o1, MemberCandidate o2) {
            return getEmailColumnValue(o1).compareToIgnoreCase(getEmailColumnValue(o2));
        }
    });
    table.addColumnSortHandler(columnSortHandler);
    // Add the columns.
    table.addColumn(statusColumn, "Status");
    table.addColumn(fullNameColumn, "Full name");
    table.addColumn(extSourceColumn, "Organization or Ext source");
    table.addColumn(emailColumn, "E-mail");
    table.addColumn(loginColumn, "Logins");
    table.addColumn(memberColumn, "Already member");
    table.addColumn(alreadyInPerunColumn, "Source");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) MemberCandidate(cz.metacentrum.perun.webgui.model.MemberCandidate) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) PerunStatusCell(cz.metacentrum.perun.webgui.widgets.cells.PerunStatusCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 3 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetCompleteRichUsers method getTable.

/**
 * Returns table of users.
 * @return
 */
public CellTable<User> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<User>(list);
    // Cell table
    table = new PerunTable<User>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // columns
    if (checkable) {
        table.addCheckBoxColumn();
    }
    table.addIdColumn("User ID", tableFieldUpdater);
    // NAME COLUMN
    Column<User, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User user) {
            return user.getFullName();
        }
    }, tableFieldUpdater);
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new Comparator<User>() {

        public int compare(User o1, User o2) {
            return o1.getLastName().compareToIgnoreCase(o2.getLastName());
        }
    });
    // Create organization column.
    Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
            String value = "";
            if (at != null) {
                value = at.getValue();
            }
            return value;
        }
    }, this.tableFieldUpdater);
    // Create e-mail column.
    Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
            String value = "";
            if (at != null) {
                value = at.getValue();
                // replace "," to " " in emails
                value = value.replace(",", " ");
            }
            return value;
        }
    }, this.tableFieldUpdater);
    // Create name column.
    Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return object.getLogins();
        }
    }, this.tableFieldUpdater);
    organizationColumn.setSortable(true);
    columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
    emailColumn.setSortable(true);
    columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
    // SERVICE COLUMN
    Column<User, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User user) {
            if (user.isServiceUser()) {
                return "Service";
            } else if (user.isSponsoredUser()) {
                return "Sponsored";
            } else {
                return "Person";
            }
        }
    }, tableFieldUpdater);
    serviceColumn.setSortable(true);
    columnSortHandler.setComparator(serviceColumn, new Comparator<User>() {

        public int compare(User o1, User o2) {
            String type1 = "Person";
            if (o1.isServiceUser()) {
                type1 = "Service";
            } else if (o1.isSponsoredUser()) {
                type1 = "Sponsored";
            }
            String type2 = "Person";
            if (o2.isServiceUser()) {
                type2 = "Service";
            } else if (o2.isSponsoredUser()) {
                type2 = "Sponsored";
            }
            return type1.compareTo(type2);
        }
    });
    // Add the other columns.
    table.addColumn(nameColumn, "Name");
    table.addColumn(organizationColumn, "Organization");
    table.addColumn(emailColumn, "E-mail");
    table.addColumn(loginsColumn, "Logins");
    table.addColumn(serviceColumn, "User type");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) User(cz.metacentrum.perun.webgui.model.User) RichUserComparator(cz.metacentrum.perun.webgui.json.comparators.RichUserComparator) Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 4 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetVos method getTable.

/**
 * Returns the table widget with VOs.
 * @return The table Widget
 */
public CellTable<VirtualOrganization> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<VirtualOrganization>(list);
    // Cell table
    table = new PerunTable<VirtualOrganization>(list);
    // prevent double loading when clicked on vo name
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<VirtualOrganization> columnSortHandler = new ListHandler<VirtualOrganization>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<VirtualOrganization>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    if (forceAll) {
        loaderImage.setEmptyResultMessage("No VOs found.");
    } else {
        loaderImage.setEmptyResultMessage("You are not manager of any VO.");
    }
    // columns
    if (checkable) {
        table.addCheckBoxColumn();
    }
    VoColumnProvider columnProvider = new VoColumnProvider(table, tableFieldUpdater);
    IsClickableCell<GeneralObject> authz = VoColumnProvider.getDefaultClickableAuthz();
    columnProvider.addIdColumn(authz, 100);
    columnProvider.addShortNameColumn(authz, 200);
    columnProvider.addNameColumn(authz);
    return table;
}
Also used : VoColumnProvider(cz.metacentrum.perun.webgui.json.columnProviders.VoColumnProvider) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 5 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class FindSimilarPublications method getEmptyTable.

/**
 * Returns table of users publications
 * @return table
 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No similar publications found.");
    // show checkbox column
    if (this.checkable) {
        // checkbox column column
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.isLocked()) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.isLocked()) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.isLocked()) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.isLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)48 Column (com.google.gwt.user.cellview.client.Column)31 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)14 Header (com.google.gwt.user.cellview.client.Header)14 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)14 Attribute (cz.metacentrum.perun.webgui.model.Attribute)12 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)12 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)8 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 TextColumn (com.google.gwt.user.cellview.client.TextColumn)6 Group (cz.metacentrum.perun.webgui.model.Group)5 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)5 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)5 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)5 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)5 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)5 Application (cz.metacentrum.perun.webgui.model.Application)4 Cell (com.google.gwt.cell.client.Cell)3 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)3 TextInputCell (com.google.gwt.cell.client.TextInputCell)3