Example usage for com.google.gwt.user.cellview.client Column setHorizontalAlignment

List of usage examples for com.google.gwt.user.cellview.client Column setHorizontalAlignment

Introduction

In this page you can find the example usage for com.google.gwt.user.cellview.client Column setHorizontalAlignment.

Prototype

@Override
public void setHorizontalAlignment(HorizontalAlignmentConstant align) 

Source Link

Document

The new horizontal alignment will apply the next time the table is rendered.

Usage

From source file:com.jitlogic.zico.client.views.traces.TraceStatsPanel.java

License:Open Source License

private void createTraceGrid() {
    grid = new DataGrid<TraceInfoStatsResult>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selection = new SingleSelectionModel<TraceInfoStatsResult>(KEY_PROVIDER);
    grid.setSelectionModel(selection);/* ww  w  . j  av  a 2  s. c o m*/

    data = new ListDataProvider<TraceInfoStatsResult>();
    data.addDataDisplay(grid);

    sortHandler = new ColumnSortEvent.ListHandler<TraceInfoStatsResult>(data.getList());
    grid.addColumnSortHandler(sortHandler);

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colTraceCalls = new IdentityColumn<TraceInfoStatsResult>(
            TRACE_CALLS_CELL);
    grid.addColumn(colTraceCalls, new ResizableHeader<TraceInfoStatsResult>("Calls", grid, colTraceCalls));
    grid.setColumnWidth(colTraceCalls, 50, Style.Unit.PX);

    colTraceCalls.setSortable(true);
    sortHandler.setComparator(colTraceCalls, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return o1.getCalls() - o2.getCalls();
        }
    });

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colTraceErrors = new IdentityColumn<TraceInfoStatsResult>(
            TRACE_ERRORS_CELL);
    grid.addColumn(colTraceErrors, new ResizableHeader<TraceInfoStatsResult>("Errors", grid, colTraceErrors));
    grid.setColumnWidth(colTraceErrors, 50, Style.Unit.PX);

    colTraceErrors.setSortable(true);
    sortHandler.setComparator(colTraceErrors, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return o1.getErrors() - o2.getErrors();
        }
    });

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colSumTime = new IdentityColumn<TraceInfoStatsResult>(
            TIME_SUM_CELL);
    grid.addColumn(colSumTime, new ResizableHeader<TraceInfoStatsResult>("Sum Time", grid, colSumTime));
    grid.setColumnWidth(colSumTime, 96, Style.Unit.PX);

    colSumTime.setSortable(true);
    sortHandler.setComparator(colSumTime, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return (int) ((o1.getSumTime() - o2.getSumTime()) / 1000000L);
        }
    });

    // avgTime

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colMinTime = new IdentityColumn<TraceInfoStatsResult>(
            TIME_MIN_CELL);
    grid.addColumn(colMinTime, new ResizableHeader<TraceInfoStatsResult>("Min Time", grid, colMinTime));
    grid.setColumnWidth(colMinTime, 96, Style.Unit.PX);

    colMinTime.setSortable(true);
    sortHandler.setComparator(colMinTime, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return (int) ((o1.getMinTime() - o2.getMinTime()) / 1000000L);
        }
    });

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colMaxTime = new IdentityColumn<TraceInfoStatsResult>(
            TIME_MAX_CELL);
    grid.addColumn(colMaxTime, new ResizableHeader<TraceInfoStatsResult>("Max Time", grid, colMaxTime));
    grid.setColumnWidth(colMaxTime, 96, Style.Unit.PX);

    colMaxTime.setSortable(true);
    sortHandler.setComparator(colMaxTime, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return (int) ((o1.getMaxTime() - o2.getMaxTime()) / 1000000L);
        }
    });

    Column<TraceInfoStatsResult, TraceInfoStatsResult> colAttr = new IdentityColumn<TraceInfoStatsResult>(
            ATTR_CELL);
    colAttr.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    grid.addColumn(colAttr, new ResizableHeader<TraceInfoStatsResult>("Attr", grid, colAttr));
    grid.setColumnWidth(colAttr, 100, Style.Unit.PCT);

    colAttr.setSortable(true);
    sortHandler.setComparator(colAttr, new Comparator<TraceInfoStatsResult>() {
        @Override
        public int compare(TraceInfoStatsResult o1, TraceInfoStatsResult o2) {
            return o1.getAttr().compareTo(o2.getAttr());
        }
    });

    grid.addCellPreviewHandler(new CellPreviewEvent.Handler<TraceInfoStatsResult>() {
        @Override
        public void onCellPreview(CellPreviewEvent<TraceInfoStatsResult> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                selection.setSelected(event.getValue(), true);
                openSearchView();
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selection.setSelected(event.getValue(), true);
                if (selection.getSelectedObject() != null) {
                    contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                            event.getNativeEvent().getClientY());
                    contextMenu.show();
                }
            }
        }
    });

    grid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());
    grid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());
}

From source file:com.stoyanr.todo.client.view.ItemsViewImpl.java

License:Open Source License

private Column<T, String> createXColumn() {
    Column<T, String> col = new Column<T, String>(new ClickableTextCell()) {

        @Override/*  ww w. j a  v a  2  s . co  m*/
        public String getValue(T t) {
            return "x";
        }
    };
    col.setFieldUpdater(new FieldUpdater<T, String>() {

        @Override
        public void update(int index, T t, String value) {
            presenter.delete(index, t);
        }

    });
    col.setCellStyleNames(X_BUTTON_STYLE);
    col.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    return col;
}

From source file:gov.nist.appvet.gwt.client.gui.table.appslist.AppsListPagingDataGrid.java

License:Open Source License

@Override
public void initTableColumns(DataGrid<T> dataGrid, ListHandler<T> sortHandler) {

    //--------------------------- App ID -----------------------------------
    final Column<T, String> appIdColumn = new Column<T, String>(new TextCell()) {

        @Override//ww  w .ja va 2 s.  c  om
        public String getValue(T object) {
            return ((AppInfoGwt) object).appId;
        }

    };
    appIdColumn.setSortable(true);
    sortHandler.setComparator(appIdColumn, new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            return ((AppInfoGwt) o1).appId.compareTo(((AppInfoGwt) o2).appId);
        }

    });
    appIdColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    dataGrid.addColumn(appIdColumn, "ID");
    dataGrid.setColumnWidth(appIdColumn, "60px");

    //--------------------------- App Icon ---------------------------------
    final SafeHtmlCell iconCell = new SafeHtmlCell();
    final Column<T, SafeHtml> iconColumn = new Column<T, SafeHtml>(iconCell) {

        @Override
        public SafeHtml getValue(T object) {
            final SafeHtmlBuilder sb = new SafeHtmlBuilder();
            final String appId = ((AppInfoGwt) object).appId;
            final AppStatus appStatus = ((AppInfoGwt) object).appStatus;
            if (appStatus == null) {
                log.warning("App status is null");
                return sb.toSafeHtml();
            } else {
                log.info("App status in table is: " + appStatus.name());
            }
            if (appStatus == AppStatus.REGISTERING) {
                iconVersion++;
                final String iconPath = appVetHostUrl + "/appvet_images/default.png?v" + iconVersion;
                sb.appendHtmlConstant("<img width=\"20\" src=\"" + iconPath + "\" alt=\"\" />");
            } else if (appStatus == AppStatus.PENDING) {
                final String iconPath = appVetHostUrl + "/appvet_images/default.png";
                sb.appendHtmlConstant("<img width=\"20\" src=\"" + iconPath + "\" alt=\"\" />");
            } else if (appStatus == AppStatus.PROCESSING) {
                iconVersion++;
                final String iconPath = appVetHostUrl + "/appvet_images/" + appId + ".png?v" + iconVersion;
                sb.appendHtmlConstant("<img width=\"20\" src=\"" + iconPath + "\" alt=\"\" />");
            } else {
                iconVersion++;
                final String iconPath = appVetHostUrl + "/appvet_images/" + appId + ".png";
                sb.appendHtmlConstant("<img width=\"20\" src=\"" + iconPath + "\" alt=\"\" />");
            }
            return sb.toSafeHtml();
        }

    };
    iconColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    iconColumn.setSortable(false);
    dataGrid.addColumn(iconColumn, "");
    dataGrid.setColumnWidth(iconColumn, "25px");

    //------------------------- App Name -----------------------------------
    final Column<T, String> appNameColumn = new Column<T, String>(new TextCell()) {

        @Override
        public String getValue(T object) {
            return ((AppInfoGwt) object).appName;
        }

    };
    appNameColumn.setSortable(true);
    sortHandler.setComparator(appNameColumn, new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            return ((AppInfoGwt) o1).appName.compareTo(((AppInfoGwt) o2).appName);
        }

    });
    appNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    dataGrid.addColumn(appNameColumn, "App");
    dataGrid.setColumnWidth(appNameColumn, "127px");

    //----------------------------- Status ---------------------------------
    final SafeHtmlCell statusCell = new SafeHtmlCell();
    final Column<T, SafeHtml> statusColumn = new Column<T, SafeHtml>(statusCell) {

        @Override
        public SafeHtml getValue(T object) {
            final SafeHtmlBuilder sb = new SafeHtmlBuilder();
            final AppStatus appStatus = ((AppInfoGwt) object).appStatus;
            String statusHtml = null;
            if (appStatus == AppStatus.ERROR) {
                statusHtml = "<div id=\"error\" style='color: red'>ERROR</div>";
            } else if (appStatus == AppStatus.WARNING) {
                statusHtml = "<div id=\"warning\" style='color: orange'>" + appStatus + "</div>";
            } else if (appStatus == AppStatus.PASS) {
                statusHtml = "<div id=\"endorsed\" style='color: green'>" + appStatus + "</div>";
            } else if (appStatus == AppStatus.FAIL) {
                statusHtml = "<div id=\"error\" style='color: red'>FAIL</div>";
            } else {
                statusHtml = "<div id=\"error\" style='color: black'>" + appStatus.name() + "</div>";
            }
            sb.appendHtmlConstant(statusHtml);
            return sb.toSafeHtml();
        }

    };
    statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    statusColumn.setSortable(true);
    sortHandler.setComparator(statusColumn, new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            return ((AppInfoGwt) o1).appStatus.compareTo(((AppInfoGwt) o2).appStatus);
        }

    });
    dataGrid.addColumn(statusColumn, "Status");
    dataGrid.setColumnWidth(statusColumn, "60px");

    //--------------------------- Submitter -------------------------------
    final Column<T, String> submitterColumn = new Column<T, String>(new TextCell()) {

        @Override
        public String getValue(T object) {
            return ((AppInfoGwt) object).userName;
        }

    };
    submitterColumn.setSortable(true);
    sortHandler.setComparator(submitterColumn, new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            return ((AppInfoGwt) o1).userName.compareTo(((AppInfoGwt) o2).userName);
        }

    });
    submitterColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    dataGrid.addColumn(submitterColumn, "User");
    dataGrid.setColumnWidth(submitterColumn, "60px");

    //--------------------------- Submit Time ------------------------------
    final Column<T, String> submitTimeColumn = new Column<T, String>(new TextCell()) {

        @Override
        public String getValue(T object) {

            final AppInfoGwt appInfo = (AppInfoGwt) object;
            final Date date = new Date(appInfo.submitTime);
            final String dateString = dateTimeFormat.format(date);
            return dateString;
        }

    };
    submitTimeColumn.setSortable(true);
    sortHandler.setComparator(submitTimeColumn, new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            final AppInfoGwt appInfo1 = (AppInfoGwt) o1;
            final Date date1 = new Date(appInfo1.submitTime);
            final String dateString1 = dateTimeFormat.format(date1);
            final AppInfoGwt appInfo2 = (AppInfoGwt) o2;
            final Date date2 = new Date(appInfo2.submitTime);
            final String dateString2 = dateTimeFormat.format(date2);
            return dateString1.compareTo(dateString2);
        }

    });
    submitTimeColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    dataGrid.addColumn(submitTimeColumn, "Date/Time");
    dataGrid.setColumnWidth(submitTimeColumn, "100px");
}

From source file:n3phele.client.view.AccountHyperlinkView.java

License:Open Source License

public AccountHyperlinkView(String uri) {
    super(new MenuItem(N3phele.n3pheleResource.accountIcon(), "Account", null),
            new MenuItem(N3phele.n3pheleResource.accountAddIcon(), "Account Edit", "account:" + uri));

    if (resource == null)
        resource = GWT.create(DataGridResource.class);

    // TABLE/*  w w w.  j a v  a  2 s.c  o m*/
    table = new FlexTable();
    table.setCellPadding(10);
    errorsOnPage = new ValidInputIndicatorWidget(
            "check for missing or invalid parameters marked with this icon", false);
    setTableData();
    table.getFlexCellFormatter().setRowSpan(0, 1, 2);
    table.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
    table.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
    table.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
    table.getColumnFormatter().setWidth(0, "220px");
    table.getColumnFormatter().setWidth(1, "290px");
    table.setCellPadding(1);
    table.setCellSpacing(1);

    // DATAGRID
    dataGrid = new DataGrid<ActivityData>(15, resource);
    dataGrid.setSize("495px", "100px");

    TextColumn<ActivityData> nameColumn = new TextColumn<ActivityData>() {
        @Override
        public String getValue(ActivityData item) {
            String result = "";
            if (item != null) {
                result += item.getName();
            }
            return result;
        }
    };
    dataGrid.addColumn(nameColumn, "Name");
    dataGrid.setColumnWidth(nameColumn, "130px");

    // TODO: Working on Activity column

    Column<ActivityData, String> activityColumn = new Column<ActivityData, String>(new ClickableTextCell()) {
        @Override
        public String getValue(ActivityData item) {

            return item.getNameTop();
        }

    };
    activityColumn.setFieldUpdater(new FieldUpdater<ActivityData, String>() {
        @Override
        public void update(int index, ActivityData obj, String value) {
            presenter.onSelect(obj);

        }
    });

    activityColumn.setCellStyleNames(N3phele.n3pheleResource.css().clickableTextCellEffect());
    dataGrid.addColumn(activityColumn, "Activity");
    dataGrid.setColumnWidth(activityColumn, "100px");

    TextColumn<ActivityData> ageColumn = new TextColumn<ActivityData>() {
        @Override
        public String getValue(ActivityData item) {
            return item.getAge();
        }
    };
    dataGrid.addColumn(ageColumn, "Age");
    dataGrid.setColumnWidth(ageColumn, "80px");

    TextColumn<ActivityData> priceColumn = new TextColumn<ActivityData>() {
        @Override
        public String getValue(ActivityData item) {
            return item.getCost();
        }
    };
    dataGrid.addColumn(priceColumn, "Total Cost");
    dataGrid.setColumnWidth(priceColumn, "75px");

    // Add a selection model to handle user selection.
    final SingleSelectionModel<ActivityData> selectionModel = new SingleSelectionModel<ActivityData>();
    dataGrid.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            selectionModel.getSelectedObject();
        }
    });

    Column<ActivityData, ActivityData> cancelColumn = new Column<ActivityData, ActivityData>(
            new CancelButtonCell<ActivityData>(new Delegate<ActivityData>() {
                @Override
                public void execute(ActivityData value) {
                    if (value != null) {
                        dataGrid.getSelectionModel().setSelected(value, false);
                        getDialog(value).show();
                    }
                }
            }, "delete virtual machine")) {
        @Override
        public ActivityData getValue(ActivityData object) {
            return object;
        }
    };
    cancelColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    dataGrid.addColumn(cancelColumn);
    dataGrid.setColumnWidth(cancelColumn, "50px");

    // CALL onModuleLoad()
    chartPanel = get();
    chartPanel.add(table);
    chartPanel.add(new SectionPanel("History"));
    chartPanel.add(historyTable);
    chartPanel.add(new SectionPanel("Active Machines"));
    chartPanel.add(vsTable);
    chartPanel = get();
    setChartTableData();
    onModuleLoad();
}

From source file:n3phele.client.view.CommandDetailView.java

License:Open Source License

public CellTable<TypedParameter> createParameterTable() {
    final ProvidesKey<TypedParameter> KEY_PROVIDER = new ProvidesKey<TypedParameter>() {
        public Object getKey(TypedParameter item) {
            return item.getName();
        }/*  w  ww  .  j a  v a2s .  c  om*/
    };
    final CellTable<TypedParameter> table;
    table = new CellTable<TypedParameter>(KEY_PROVIDER);
    table.setWidth("100%");
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    TextColumn<TypedParameter> descriptionColumn = new TextColumn<TypedParameter>() {
        @Override
        public String getValue(TypedParameter command) {
            String result = "";
            if (command != null)
                return command.getDescription();
            return result;
        }
    };
    table.addColumn(descriptionColumn);

    this.parameterTextInputCell = new DisappearingTextInputCell();
    this.parameterCheckboxCell = new DisappearingCheckBoxCell();
    final ValidInputIndicatorCell valid = new ValidInputIndicatorCell(N3phele.n3pheleResource.inputErrorIcon());

    HasCell<TypedParameter, ?> valueHasCell = new HasCell<TypedParameter, String>() {

        @Override
        public Cell<String> getCell() {
            return CommandDetailView.this.parameterTextInputCell;
        }

        @Override
        public FieldUpdater<TypedParameter, String> getFieldUpdater() {
            return new FieldUpdater<TypedParameter, String>() { // Needs to exist so that the cell level updater is invoked
                @Override
                public void update(int index, TypedParameter object, String value) {
                }

            };
        }

        @Override
        public String getValue(TypedParameter object) {
            if (object != null) {
                if (!object.getType().equalsIgnoreCase("boolean")) {
                    String result = object.getValue();
                    if (isNullOrBlank(result))
                        result = object.getDefaultValue();
                    if (result == null)
                        result = "";
                    return result;
                }
            }
            return null;
        }

    };
    HasCell<TypedParameter, ?> validHasCell = new HasCell<TypedParameter, String>() {

        @Override
        public Cell<String> getCell() {
            return valid;
        }

        @Override
        public FieldUpdater<TypedParameter, String> getFieldUpdater() {
            return null;
        }

        @Override
        public String getValue(TypedParameter object) {
            String errTooltip;
            errTooltip = errorMessageMap().get(object.getType());
            if (checkParameterValue(object)) {
                return "-" + errTooltip;
            } else {
                return "+" + errTooltip;
            }
        }

    };

    HasCell<TypedParameter, ?> booleanHasCell = new HasCell<TypedParameter, Boolean>() {

        @Override
        public Cell<Boolean> getCell() {
            return parameterCheckboxCell;
        }

        @Override
        public FieldUpdater<TypedParameter, Boolean> getFieldUpdater() {
            return new FieldUpdater<TypedParameter, Boolean>() { // Needs to exist so that the cell level updater is invoked
                @Override
                public void update(int index, TypedParameter object, Boolean value) {
                }

            };
        }

        @Override
        public Boolean getValue(TypedParameter object) {
            if (object != null) {
                if (object.getType().equalsIgnoreCase("boolean")) {
                    String result = object.getValue();
                    if (isNullOrBlank(result))
                        result = object.getDefaultValue();
                    return Boolean.valueOf(result);
                }
            }
            return null;
        }

    };
    List<HasCell<TypedParameter, ?>> arg = new ArrayList<HasCell<TypedParameter, ?>>(2);
    arg.add(validHasCell);
    arg.add(valueHasCell);
    arg.add(booleanHasCell);

    Column<TypedParameter, TypedParameter> valueColumn = new Column<TypedParameter, TypedParameter>(
            new TypedPropertyComposite(arg)) {
        @Override
        public TypedParameter getValue(TypedParameter parameter) {
            return parameter;
        }
    };
    valueColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    table.addColumn(valueColumn);
    table.setWidth("100%", true);
    table.setColumnWidth(valueColumn, "210px");
    valueColumn.setFieldUpdater(new FieldUpdater<TypedParameter, TypedParameter>() {
        public void update(int index, final TypedParameter object, final TypedParameter value) {
            GWT.runAsync(new RunAsyncCallback() {

                @Override
                public void onSuccess() {
                    updateRunButton(true);
                }

                @Override
                public void onFailure(Throwable reason) {
                    //
                }
            });

        }
    });
    return table;
}

From source file:n3phele.client.view.CommandDetailView.java

License:Open Source License

public CellTable<FileSpecification> createFileTable(Column<FileSpecification, FileSpecification> repoColumn) {
    final ProvidesKey<FileSpecification> KEY_PROVIDER = new ProvidesKey<FileSpecification>() {

        public Object getKey(FileSpecification item) {
            return item.getName();
        }/*from  w  w w  .j a v a  2  s.com*/
    };
    final CellTable<FileSpecification> table;
    table = new CellTable<FileSpecification>(KEY_PROVIDER);
    table.setWidth("100%", true);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    TextColumn<FileSpecification> descriptionColumn = new TextColumn<FileSpecification>() {
        @Override
        public String getValue(FileSpecification file) {
            String result = "";
            if (file != null)
                return file.getDescription();
            return result;
        }
    };
    table.addColumn(descriptionColumn);

    table.addColumn(repoColumn);
    repoColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    return table;
}

From source file:n3phele.client.view.CommandDetailView.java

License:Open Source License

protected Column<FileSpecification, FileSpecification> replaceSelectionRepoColumn(
        CellTable<FileSpecification> table, Column<FileSpecification, FileSpecification> newColumn,
        Column<FileSpecification, FileSpecification> repoColumn) {
    int index = table.getColumnIndex(repoColumn);
    table.removeColumn(index);//from ww  w . j  a  va  2s .c  om
    table.insertColumn(index, newColumn);
    newColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    return newColumn;
}

From source file:n3phele.client.view.ProcessView.java

License:Open Source License

public ProcessView() {
    super(new MenuItem(N3phele.n3pheleResource.activityIcon(), "Activity", null));
    table = new FlexTable();
    table.setCellPadding(2);/*from   w  w  w. ja v  a2s.  c om*/

    this.add(table);
    table.setWidth("100%");

    Label lblNewLabel_4 = new Label("name");
    table.setWidget(0, 0, lblNewLabel_4);

    name = new Label("");
    table.setWidget(0, 1, name);

    iconStatus = new CellWidget<IconText>(new IconTextCell<IconText>(32, 32, 15));
    table.setWidget(0, 2, iconStatus);
    table.getColumnFormatter().setWidth(0, "60px");
    table.getColumnFormatter().setWidth(2, "170px");

    Label lblNewLabel = new Label("running");
    table.setWidget(1, 0, lblNewLabel);

    command = new Hyperlink("", "");
    table.setWidget(1, 1, command);
    table.getFlexCellFormatter().setColSpan(1, 1, 2);

    //      description = new Label("-description-");
    //      table.setWidget(1, 2, description);

    Label lblNewLabel_3 = new Label("started");
    table.setWidget(2, 0, lblNewLabel_3);

    startdate = new CellWidget<Date>(
            new DateCell(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT)));

    table.setWidget(2, 1, startdate);
    //table.getFlexCellFormatter().setColSpan(2, 1, 2);

    Label lblNewLabel_6 = new Label("completed");
    table.setWidget(3, 0, lblNewLabel_6);

    completedate = new CellWidget<Date>(
            new DateCell(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT)));
    table.setWidget(3, 1, completedate);
    //table.getFlexCellFormatter().setColSpan(3, 1, 2);

    duration = new Label(".duration");
    table.setWidget(3, 2, duration);

    if (resource == null)
        resource = GWT.create(NarrativeListCellTableResource.class);
    narrativeTable = new CellTable<Narrative>(15, resource);
    this.add(narrativeTable);
    narrativeTable.setWidth("100%", true);

    final Map<String, ImageResource> mapper = new HashMap<String, ImageResource>();
    mapper.put("info", N3phele.n3pheleResource.narrativeInfo());
    mapper.put("warning", N3phele.n3pheleResource.narrativeWarning());
    mapper.put("error", N3phele.n3pheleResource.narrativeError());
    state = new Column<Narrative, ImageResource>(new ImageResourceCell()) {
        @Override
        public ImageResource getValue(Narrative object) {
            return mapper.get(object.getState());
        }
    };
    state.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    state.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    narrativeTable.addColumn(state);
    narrativeTable.setColumnWidth(state, "8%");

    Column<Narrative, Date> date = new Column<Narrative, Date>(
            new DateCell(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT))) {
        @Override
        public Date getValue(Narrative object) {
            return object.getStamp();
        }
    };
    narrativeTable.addColumn(date);
    narrativeTable.setColumnWidth(date, "15%");

    Column<Narrative, Hyperlink> id = new Column<Narrative, Hyperlink>(new HyperlinkCell()) {

        @Override
        public Hyperlink getValue(Narrative object) {
            if (object == null)
                return null;
            String name = object.getTag();
            String historyToken = presenter.getToken(object.getProcessUri());
            return new Hyperlink(name, historyToken);
        }

    };
    id.setFieldUpdater(new FieldUpdater<Narrative, Hyperlink>() {
        @Override
        public void update(int index, Narrative object, Hyperlink value) {
            ProcessView.this.narrativeTable.setFocus(false);
        }
    });
    id.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    id.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    narrativeTable.addColumn(id);
    narrativeTable.setColumnWidth(id, "20%");

    TextColumn<Narrative> msg = new TextColumn<Narrative>() {
        @Override
        public String getValue(Narrative object) {
            return object.getText();
        }
    };
    msg.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    msg.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    narrativeTable.addColumn(msg);
    narrativeTable.setColumnWidth(msg, "60%");
}

From source file:org.eclipse.che.ide.ext.git.client.reset.files.ResetFilesViewImpl.java

License:Open Source License

/** Initialize the columns of the grid. */
private void initColumns() {
    indexFiles = new CellTable<IndexFile>();

    // Create files column:
    Column<IndexFile, String> filesColumn = new Column<IndexFile, String>(new TextCell()) {
        @Override//from w  w  w. ja  v a 2s.  c  o m
        public String getValue(IndexFile file) {
            return file.getPath();
        }
    };

    // Create column with checkboxes:
    Column<IndexFile, Boolean> checkColumn = new Column<IndexFile, Boolean>(new CheckboxCell(false, true)) {
        @Override
        public Boolean getValue(IndexFile file) {
            return !file.isIndexed();
        }
    };

    // Create bean value updater:
    FieldUpdater<IndexFile, Boolean> checkFieldUpdater = new FieldUpdater<IndexFile, Boolean>() {
        @Override
        public void update(int index, IndexFile file, Boolean value) {
            file.setIndexed(!value);
        }
    };

    checkColumn.setFieldUpdater(checkFieldUpdater);

    filesColumn.setHorizontalAlignment(ALIGN_LEFT);

    indexFiles.addColumn(checkColumn, new SafeHtml() {
        @Override
        public String asString() {
            return "&nbsp;";
        }
    });
    indexFiles.setColumnWidth(checkColumn, 1, Style.Unit.PCT);
    indexFiles.addColumn(filesColumn, FILES);
    indexFiles.setColumnWidth(filesColumn, 35, Style.Unit.PCT);
    indexFiles.addStyleName(resources.gitCSS().cells());
}

From source file:org.eclipse.che.ide.ext.openshift.client.deploy._new.NewApplicationViewImpl.java

License:Open Source License

private CellTable<KeyValue> createCellTable(CellTableResources cellTableResources,
        final ListDataProvider<KeyValue> dataProvider, final Predicate<String> keyValidator,
        final Predicate<String> valueValidator) {
    final CellTable<KeyValue> table = new CellTable<>(50, cellTableResources);
    table.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataProvider.addDataDisplay(table);// w  w  w  .j  a  v  a 2s.  com

    TextInputCell keyCell = new TextInputCell() {
        @Override
        public void onBrowserEvent(Context context, com.google.gwt.dom.client.Element parent, String value,
                NativeEvent event, ValueUpdater<String> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if (event.getType().equals(BrowserEvents.KEYUP)) {
                String newValue = getInputElement(parent).getValue();
                if (!keyValidator.apply(newValue)) {
                    parent.getParentElement().addClassName(resources.css().deployApplicationTableError());
                } else {
                    parent.getParentElement().removeClassName(resources.css().deployApplicationTableError());
                }
                valueUpdater.update(newValue);
                delegate.updateControls();
            }
        }
    };

    Column<KeyValue, String> nameColumn = new Column<KeyValue, String>(keyCell) {
        @Override
        public String getCellStyleNames(Cell.Context context, KeyValue object) {
            if (!keyValidator.apply(object.getKey())) {
                return resources.css().deployApplicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue object) {
            return object.getKey();
        }
    };

    nameColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue object, String value) {
            object.setKey(value);
        }
    });

    TextInputCell valueCell = new TextInputCell() {
        @Override
        public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, String value,
                NativeEvent event, ValueUpdater<String> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if (event.getType().equals(BrowserEvents.KEYUP)) {
                String newValue = getInputElement(parent).getValue();
                if (!valueValidator.apply(newValue)) {
                    parent.getParentElement().addClassName(resources.css().deployApplicationTableError());
                } else {
                    parent.getParentElement().removeClassName(resources.css().deployApplicationTableError());
                }
                valueUpdater.update(newValue);
                delegate.updateControls();
            }
        }
    };

    Column<KeyValue, String> valueColumn = new Column<KeyValue, String>(valueCell) {
        @Override
        public String getCellStyleNames(Cell.Context context, KeyValue object) {
            if (!valueValidator.apply(object.getValue())) {
                return resources.css().deployApplicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue object) {
            return object.getValue();
        }
    };

    valueColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue object, String value) {
            object.setValue(value);
        }
    });

    Column<KeyValue, String> removeColumn = new Column<KeyValue, String>(new ButtonCell()) {
        @Override
        public String getValue(KeyValue object) {
            return "-";
        }

        @Override
        public void render(Cell.Context context, KeyValue object, SafeHtmlBuilder sb) {
            Button removeButton = new Button();
            super.render(context, object, sb.appendHtmlConstant(removeButton.getHTML()));
        }
    };

    removeColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue object, String value) {
            dataProvider.getList().remove(object);
            delegate.updateControls();
        }
    });

    table.addColumn(nameColumn);
    table.setColumnWidth(nameColumn, 35, Style.Unit.PCT);
    table.addColumn(valueColumn);
    table.setColumnWidth(valueColumn, 55, Style.Unit.PCT);
    table.addColumn(removeColumn);
    table.setColumnWidth(removeColumn, 10, Style.Unit.PCT);
    removeColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    return table;
}