Example usage for com.google.gwt.user.client Cookies getCookie

List of usage examples for com.google.gwt.user.client Cookies getCookie

Introduction

In this page you can find the example usage for com.google.gwt.user.client Cookies getCookie.

Prototype

public static String getCookie(String name) 

Source Link

Document

Gets the cookie associated with the given name.

Usage

From source file:org.spiffyui.hellospiffyoauth.client.Index.java

License:Apache License

/**
  * returns whether the  user is logged in or not
  * @return true if the user is logged in (browser cookie is there)
  *///from w  w  w  .j ava  2s.c o  m
private boolean userLoggedIn() {
    String oauthVerifier = Window.Location.getParameter(OAUTH_VERIFIER);
    String oauthToken = Window.Location.getParameter(OAUTH_TOKEN);

    boolean urlParams = !isEmpty(oauthVerifier) && !isEmpty(oauthToken);
    if (urlParams) {
        /*
         * If there are url params, set them in the cookie so if the browser is refreshed, we can use them again.
         */
        Cookies.setCookie(OAUTH_TOKEN, oauthToken);
        Cookies.setCookie(OAUTH_VERIFIER, oauthVerifier);
        return true;
    }

    /*
     * If there were no url params, check the cookie.
     */
    String tokenCookie = Cookies.getCookie(OAUTH_TOKEN);
    String verifCookie = Cookies.getCookie(OAUTH_VERIFIER);
    return !isEmpty(tokenCookie) && !isEmpty(verifCookie);
}

From source file:org.t3as.snomedct.gwt.client.gwt.AnalyseHandler.java

License:Open Source License

public AnalyseHandler(final TextArea mainTextArea, final Label statusLabel,
        final List<SnomedConcept> conceptList, final List<SemanticType> types,
        final Map<String, String> typeCodeToDescription) {
    this.mainTextArea = mainTextArea;
    this.statusLabel = statusLabel;
    this.conceptList = conceptList;
    this.types = types;
    this.typeCodeToDescription = typeCodeToDescription;
    this.glassPanel = new GlassLoadingPanel();

    final String hostAndPort = Cookies.getCookie("webserviceHost");
    this.webserviceUrl = (hostAndPort.isEmpty() ? "" : "http://" + hostAndPort)
            + "/snomed-coder-web/rest/v1.0/snomedctCodes";
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.BulkUpdateListPanel.java

License:Open Source License

private ContentPanel generateGrid() {
    gridContainer = new ContentPanel(new FitLayout());

    ColumnModel cm = new ColumnModel(generateColumnList());
    gridContainer.setBodyBorder(false);/*from  w  ww .j  a  v  a 2  s . co m*/
    gridContainer.setHeaderVisible(false);

    loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
    loader.setRemoteSort(true);

    store = new ListStore<ItemBean>(loader);
    store.setKeyProvider(keyProvidernew);

    loader.addLoadListener(new LoadListener() {

        @Override
        public void loaderLoad(LoadEvent le) {
            if (store.getModels().size() > 0) {
                grid.getSelectionModel().select(0, false);
            }
        }
    });

    int usePageSize = Constants.PAGE_SIZE;
    if (Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE) != null) {
        usePageSize = Integer.parseInt(Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE));
    }

    pagingBar = new PagingToolBarEx(usePageSize) {

        @Override
        protected void onLoad(LoadEvent event) {
            String of_word = MessagesFactory.getMessages().of_word();
            msgs.setDisplayMsg("{0} - {1} " + of_word + " " + (isPagingAccurate ? "" : "~") + "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
            super.onLoad(event);
        }
    };
    pagingBar.setBrowseRecordsGridCall(true);
    pagingBar.setHideMode(HideMode.VISIBILITY);
    pagingBar.getMessages().setDisplayMsg(MessagesFactory.getMessages().page_displaying_records());

    pagingBar.setVisible(false);
    pagingBar.bind(loader);
    gridContainer.setBottomComponent(pagingBar);
    grid = new ColumnAlignGrid<ItemBean>(store, cm);

    {
        grid.setStateful(true);
        AppHeader header = (AppHeader) BrowseRecords.getSession().get(UserSession.APP_HEADER);
        ViewBean vb = (ViewBean) BrowseRecords.getSession().get(UserSession.CURRENT_VIEW);
        grid.setStateId(header.getDatamodel() + "." + entityModel.getConceptName() + "." + vb.getViewPK()); //$NON-NLS-1$//$NON-NLS-2$
    }

    grid.getView().setForceFit(true);
    if (cm.getColumnCount() > 0) {
        grid.setAutoExpandColumn(cm.getColumn(0).getHeader());
    }

    grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ItemBean>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<ItemBean> se) {
            selectRow(se.getSelectedItem());
        }
    });

    grid.setLoadMask(true);

    grid.getAriaSupport().setDescribedBy("abcdefg"); //$NON-NLS-1$
    grid.getAriaSupport().setLabelledBy(this.getHeader().getId() + "-label"); //$NON-NLS-1$

    grid.addPlugin(filters);
    gridContainer.add(grid);

    return gridContainer;
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.ForeignKey.ForeignKeyListWindow.java

License:Open Source License

@Override
protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    final PagingLoadConfig config = new BasePagingLoadConfig();
    final TypeModel typeModel = sourceField.getDataType();
    final String originalForeignkey = typeModel.getForeignkey();
    RpcProxy<PagingLoadResult<ForeignKeyBean>> proxy = new RpcProxy<PagingLoadResult<ForeignKeyBean>>() {

        @Override/*from  ww w .jav  a2s . co  m*/
        public void load(final Object loadConfig,
                final AsyncCallback<PagingLoadResult<ForeignKeyBean>> callback) {
            PagingLoadConfig config = (PagingLoadConfig) loadConfig;
            if (pageToolBar != null) {
                config.setLimit(pageToolBar.getPageSize());
            }
            BasePagingLoadConfigImpl baseConfig = BasePagingLoadConfigImpl.copyPagingLoad(config);
            final String currentFilterText = getFilterValue();

            baseConfig.set("language", Locale.getLanguage()); //$NON-NLS-1$

            typeModel.setForeignkey(foreignKeyPath);
            typeModel.setFilterValue(currentFilterText);
            service.getForeignKeyList(baseConfig, typeModel,
                    org.talend.mdm.webapp.base.shared.util.CommonUtil.unescapeXml(foreignKeyFilterValue),
                    dataCluster, Locale.getLanguage(),
                    new SessionAwareAsyncCallback<ItemBasePageLoadResult<ForeignKeyBean>>() {

                        @Override
                        protected void doOnFailure(Throwable caught) {
                            String err = caught.getMessage();
                            if (err != null) {
                                MessageBox.alert(MessagesFactory.getMessages().error_title(),
                                        MultilanguageMessageParser.pickOutISOMessage(err), null);
                                callback.onSuccess(new BasePagingLoadResult<ForeignKeyBean>(
                                        new ArrayList<ForeignKeyBean>(), 0, 0));
                            } else {
                                callback.onFailure(caught);
                            }
                            typeModel.setForeignkey(originalForeignkey);
                        }

                        @Override
                        public void onSuccess(ItemBasePageLoadResult<ForeignKeyBean> result) {
                            if (currentFilterText.equals(getFilterValue())) {
                                callback.onSuccess(new BasePagingLoadResult<ForeignKeyBean>(result.getData(),
                                        result.getOffset(), result.getTotalLength()));
                            }
                            typeModel.setForeignkey(originalForeignkey);
                        }

                    });
        }
    };

    RpcProxy<BaseListLoadResult<BaseModel>> proxy1 = new RpcProxy<BaseListLoadResult<BaseModel>>() {

        @Override
        public void load(final Object loadConfig, final AsyncCallback<BaseListLoadResult<BaseModel>> callback) {
            service.getForeignKeyPolymTypeList(ForeignKeyListWindow.this.foreignKeyPath, Locale.getLanguage(),
                    new SessionAwareAsyncCallback<List<Restriction>>() {

                        @Override
                        protected void doOnFailure(Throwable caught) {
                            callback.onFailure(caught);
                        }

                        @Override
                        public void onSuccess(List<Restriction> result) {
                            List<BaseModel> list = new ArrayList<BaseModel>();
                            for (Restriction re : result) {
                                BaseModel model = new BaseModel();
                                model.set("name", re.getName());//$NON-NLS-1$
                                model.set("value", re.getValue());//$NON-NLS-1$
                                list.add(model);
                            }
                            callback.onSuccess(new BaseListLoadResult<BaseModel>(list));
                        }
                    });
        }
    };
    BaseListLoader<ListLoadResult<Restriction>> loader1 = new BaseListLoader<ListLoadResult<Restriction>>(
            proxy1);
    typeList = new ListStore<BaseModel>(loader1);
    loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
    loader.setRemoteSort(true);
    final ListStore<ForeignKeyBean> store = new ListStore<ForeignKeyBean>(loader);

    int usePageSize = Constants.PAGE_SIZE;
    if (Cookies.getCookie(PagingToolBarEx.BROWSERECORD_FOREIGNKEY_PAGESIZE) != null) {
        usePageSize = Integer.parseInt(Cookies.getCookie(PagingToolBarEx.BROWSERECORD_FOREIGNKEY_PAGESIZE));
    }
    pageToolBar = new PagingToolBarEx(usePageSize, PagingToolBarEx.BROWSERECORD_FOREIGNKEY_PAGESIZE) {

        @Override
        protected void onLoad(LoadEvent event) {
            String of_word = MessagesFactory.getMessages().of_word();
            msgs.setDisplayMsg("{0} - {1} " + of_word + " " + "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
            super.onLoad(event);
        }
    };
    pageToolBar.setBrowseRecordsGridCall(true);
    pageToolBar.bind(loader);
    pageToolBar.setEnabled(true);

    FormPanel panel = new FormPanel();
    panel.setFrame(false);
    panel.setLayout(new FitLayout());
    panel.setHeaderVisible(false);
    panel.setSize(WINDOW_WIDTH, WINDOW_HEIGH);
    panel.setHeaderVisible(false);

    filter.addListener(Events.KeyUp, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            if (be.getKeyCode() == KeyCodes.KEY_UP) {
                ForeignKeyBean fkBean = grid.getSelectionModel().getSelectedItem();
                if (fkBean == null) {
                    grid.getSelectionModel().select(store.getCount() - 1, true);
                } else {
                    grid.getSelectionModel().selectPrevious(false);
                    filter.focus();
                }
                return;
            }
            if (be.getKeyCode() == KeyCodes.KEY_DOWN) {
                ForeignKeyBean fkBean = grid.getSelectionModel().getSelectedItem();
                if (fkBean == null) {
                    grid.getSelectionModel().select(0, true);
                } else {
                    grid.getSelectionModel().selectNext(false);
                    filter.focus();
                }
                return;
            }
            if (be.getKeyCode() == KeyCodes.KEY_ENTER) {
                if (filter.getRawValue().equals(previousFilterText)) {
                    ForeignKeyBean fkBean = grid.getSelectionModel().getSelectedItem();
                    fkBean.setForeignKeyPath(entityModel.getConceptName());
                    fkBean.setDisplayInfo(fkBean.toString() != null ? fkBean.toString() : fkBean.getId());
                    returnCriteriaFK.setCriteriaFK(fkBean);
                    closeOrHideWindow();
                } else {
                    previousFilterText = filter.getRawValue();
                    loader.load(0, pageToolBar.getPageSize());
                }

            }
            if (be.getKeyCode() == KeyCodes.KEY_LEFT || be.getKeyCode() == KeyCodes.KEY_RIGHT) {
                return;
            }
        }
    });
    filter.setWidth(WINDOW_WIDTH - 80);

    ToolBar toolBar = new ToolBar();

    typeComboBox = new ComboBoxField<BaseModel>();
    typeComboBox.setRawValue(entityModel.getConceptName());
    typeComboBox.setDisplayField("name"); //$NON-NLS-1$
    typeComboBox.setValueField("value"); //$NON-NLS-1$
    typeComboBox.setStore(typeList);
    typeComboBox.setTriggerAction(TriggerAction.ALL);
    typeComboBox.setEmptyText(MessagesFactory.getMessages().label_select_type());
    typeComboBox.setId("DerivedTypeComboBox"); //$NON-NLS-1$

    typeComboBox.addSelectionChangedListener(new SelectionChangedListener<BaseModel>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<BaseModel> se) {
            String targetEntity = se.getSelectedItem().get("value").toString();//$NON-NLS-1$
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < ForeignKeyListWindow.this.foreignKeyInfo.size(); i++) {
                sb.append(ForeignKeyListWindow.this.foreignKeyInfo.get(i));
                if (i < ForeignKeyListWindow.this.foreignKeyInfo.size() - 1 && i >= 0) {
                    sb.append(",");//$NON-NLS-1$
                }
            }
            String fkInfo = sb.toString();
            ForeignKeyDrawer fkDrawer = CommonUtil.switchForeignKeyEntityType(targetEntity,
                    ForeignKeyListWindow.this.foreignKeyPath, fkInfo);
            ForeignKeyListWindow.this.foreignKeyPath = fkDrawer.getXpathForeignKey();
            List<String> fkinfo = new ArrayList<String>();
            if (fkDrawer.getXpathInfoForeignKey() != null) {
                String[] foreignKeyList = fkDrawer.getXpathInfoForeignKey().split(","); //$NON-NLS-1$
                for (String info : foreignKeyList) {
                    fkinfo.add(info);
                }
            }
            ForeignKeyListWindow.this.foreignKeyInfo = fkinfo;
            loader.load(0, pageToolBar.getPageSize());
            if (entityModel != null && targetEntity != null
                    && !targetEntity.equals(entityModel.getConceptName())) {
                fkDrawer = CommonUtil.switchForeignKeyEntityType(entityModel.getConceptName(),
                        ForeignKeyListWindow.this.foreignKeyPath, fkInfo);
                ForeignKeyListWindow.this.foreignKeyPath = fkDrawer.getXpathForeignKey();
            }
        }
    });
    toolBar.add(typeComboBox);

    Button filterBtn = new Button();
    filterBtn.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.funnel()));
    filterBtn.setWidth(30);
    filterBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            loader.load(0, pageToolBar.getPageSize());
        }
    });
    filter.setWidth(200);
    typeComboBox.setWidth(WINDOW_WIDTH - 250);
    toolBar.add(filter);
    toolBar.add(filterBtn);
    panel.setTopComponent(toolBar);

    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    // build columns by specify store

    // change label display
    // boolean retrieveFKinfos = typeModel.isRetrieveFKinfos();
    boolean isDisplayKeyInfo = false;
    if (this.foreignKeyInfo.size() > 0) {
        List<String> foreignKeyInfo = this.foreignKeyInfo;
        if (foreignKeyInfo.contains(this.foreignKeyPath)) {
            isDisplayKeyInfo = true;
        }
        Map<String, TypeModel> dataTypes = entityModel.getMetaDataTypes();
        for (String info : foreignKeyInfo) {
            TypeModel metaDataType = dataTypes.get(info);
            ColumnConfig columnConfig = new ColumnConfig(info,
                    metaDataType == null ? info : ViewUtil.getViewableLabel(Locale.getLanguage(), metaDataType),
                    COLUMN_WIDTH);
            columns.add(columnConfig);
            if (entityModel.getTypeModel(info).getType().equals(DataTypeConstants.MLS)) {

                columnConfig.setRenderer(new GridCellRenderer<ForeignKeyBean>() {

                    @Override
                    public Object render(final ForeignKeyBean fkBean, String property, ColumnData config,
                            int rowIndex, int colIndex, ListStore<ForeignKeyBean> store,
                            Grid<ForeignKeyBean> grid) {
                        String multiLanguageString = (String) fkBean.get(property);
                        MultiLanguageModel multiLanguageModel = new MultiLanguageModel(multiLanguageString);
                        return Format.htmlEncode(
                                multiLanguageModel.getValueByLanguage(Locale.getLanguage().toUpperCase()));
                    }
                });

            } else {
                columnConfig.setRenderer(new GridCellRenderer<ForeignKeyBean>() {

                    @Override
                    public Object render(final ForeignKeyBean fkBean, String property, ColumnData config,
                            int rowIndex, int colIndex, ListStore<ForeignKeyBean> store,
                            Grid<ForeignKeyBean> grid) {
                        String propertyName = CommonUtil.getElementFromXpath(property);
                        return fkBean.get(propertyName);
                    }
                });
            }
        }
        if (columns.size() > 0) {
            config.setSortField(columns.get(0).getId());
            config.setSortDir(SortDir.ASC);
        }
    }
    if (columns.size() == 0) {
        columns.add(new ColumnConfig("id", CommonUtil.getElementFromXpath(typeModel.getXpath()), COLUMN_WIDTH)); //$NON-NLS-1$
        isDisplayKeyInfo = true;
    }

    // fix bug TMDM-2829
    if (!isDisplayKeyInfo) {
        ColumnConfig columnConfig = columns.get(0);
        final String fkInfo = this.foreignKeyInfo.get(0);
        columnConfig.setRenderer(new GridCellRenderer<ForeignKeyBean>() {

            @Override
            public Object render(final ForeignKeyBean fkBean, String property, ColumnData config, int rowIndex,
                    int colIndex, ListStore<ForeignKeyBean> store, Grid<ForeignKeyBean> grid) {
                String result = ""; //$NON-NLS-1$
                if (fkBean != null) {
                    String propertyName = CommonUtil.getElementFromXpath(property);
                    if (fkBean.get(propertyName) != null && !"".equals(fkBean.get(propertyName))) { //$NON-NLS-1$
                        if (entityModel.getTypeModel(fkInfo).getType().equals(DataTypeConstants.MLS)) {
                            MultiLanguageModel multiLanguageModel = new MultiLanguageModel(
                                    fkBean.get(propertyName).toString());
                            result = multiLanguageModel.getValueByLanguage(Locale.getLanguage().toUpperCase())
                                    + "-"; //$NON-NLS-1$
                        } else {
                            if (fkBean.getDisplayInfo() != null && fkBean.getDisplayInfo().length() > 0) {
                                result = fkBean.getDisplayInfo() + "-"; //$NON-NLS-1$
                            } else {
                                result = fkBean.get(propertyName) + "-"; //$NON-NLS-1$
                            }
                        }
                    }
                    return result = result + fkBean.getId();
                }
                return result;
            }
        });
    }

    ColumnModel cm = new ColumnModel(columns);
    grid = new Grid<ForeignKeyBean>(store, cm);
    grid.getView().setForceFit(true);
    grid.setLoadMask(true);
    grid.setBorders(false);
    grid.setStateful(true);
    grid.setStateId("relatedRecordGrid"); //$NON-NLS-1$
    grid.addListener(Events.Attach, new Listener<GridEvent<ForeignKeyBean>>() {

        @Override
        public void handleEvent(GridEvent<ForeignKeyBean> be) {
            config.setOffset(0);
            config.setLimit(pageToolBar.getPageSize());
            loader.load(config);
        }
    });

    grid.addListener(Events.OnDoubleClick, new Listener<GridEvent<ForeignKeyBean>>() {

        @Override
        public void handleEvent(final GridEvent<ForeignKeyBean> be) {
            ForeignKeyBean fkBean = be.getModel();
            fkBean.setForeignKeyPath(entityModel.getConceptName());
            CommonUtil.setForeignKeyDisplayInfo(fkBean);
            sourceField.setValue(fkBean);
            typeComboBox.setRawValue(null);
            closeOrHideWindow();
        }
    });

    panel.add(grid);
    panel.setBottomComponent(pageToolBar);

    Button cancelBtn = new Button(MessagesFactory.getMessages().cancel_btn());
    cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            closeOrHideWindow();
        }
    });
    addButton(cancelBtn);
    add(panel, new FlowData(5));
    addListener(Events.Resize, new Listener<WindowEvent>() {

        @Override
        public void handleEvent(WindowEvent e) {
            recalculate(e.getHeight(), e.getWidth());
        }
    });
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.GenerateContainer.java

License:Open Source License

public static void setDefaultView() {
    String parameter = Cookies.getCookie(PortletConstants.PARAMETER_ENTITY);
    Cookies.removeCookie(PortletConstants.PARAMETER_ENTITY);
    setDefaultViewPk(parameter == null ? "" : parameter); //$NON-NLS-1$
    if (parameter != null) {
        BrowseRecordsServiceAsync service = (BrowseRecordsServiceAsync) Registry
                .get(BrowseRecords.BROWSERECORDS_SERVICE);
        service.getAppHeader(new SessionAwareAsyncCallback<AppHeader>() {

            @Override//from   w  w  w . j av a 2  s.c om
            public void onSuccess(AppHeader header) {
                if (header.getDatacluster() == null || header.getDatamodel() == null) {
                    MessageBox.alert(MessagesFactory.getMessages().error_title(),
                            MessagesFactory.getMessages().data_model_not_specified(), null);
                    return;
                }
                BrowseRecords.getSession().put(UserSession.APP_HEADER, header);
                Dispatcher dispatcher = Dispatcher.get();
                dispatcher.dispatch(BrowseRecordsEvents.DefaultView);
            }
        });
    }
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.ItemsListPanel.java

License:Open Source License

public void updateGrid(CheckBoxSelectionModel<ItemBean> sm, List<ColumnConfig> columnConfigList) {
    // toolBar.searchBut.setEnabled(false);
    if (gridContainer != null && this.findItem(gridContainer.getElement()) != null) {
        remove(gridContainer);/*from ww w .j av  a2s.c  om*/
    }
    if (panel != null && this.findItem(panel.getElement()) != null) {
        remove(panel);
    }

    ColumnModel cm = new ColumnModel(columnConfigList);
    gridContainer = new ContentPanel(new FitLayout());
    gridContainer.setBodyBorder(false);
    gridContainer.setHeaderVisible(false);

    loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
    loader.setRemoteSort(true);

    store = new ListStore<ItemBean>(loader);
    store.setKeyProvider(keyProvidernew);

    loader.addLoadListener(new LoadListener() {

        @Override
        public void loaderLoad(LoadEvent le) {
            if (store.getModels().size() > 0) {
                if (selectedItems == null) {
                    // search and create
                    if (isCreate && createItemBean != null) {
                        ItemBean findModel = grid.getStore().findModel(createItemBean.getIds());
                        if (findModel != null) {
                            grid.getSelectionModel().select(findModel, true);
                        } else {
                            grid.getSelectionModel().select(-1, false);
                        }
                    } else {
                        grid.getSelectionModel().select(0, false);
                    }
                    isCreate = false;
                    createItemBean = null;
                }
            } else {
                ItemsToolBar.getInstance().searchButton.setEnabled(true);
                // ItemsMainTabPanel.getInstance().getCurrentViewTabItem().clearAll();
            }
            if (reLoad != null) {
                reLoad.onReLoadData();
            }
        }
    });

    int usePageSize = Constants.PAGE_SIZE;
    if (Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE) != null) {
        usePageSize = Integer.parseInt(Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE));
    }

    pagingBar = new PagingToolBarEx(usePageSize) {

        @Override
        protected void onLoad(LoadEvent event) {
            String of_word = MessagesFactory.getMessages().of_word();
            msgs.setDisplayMsg("{0} - {1} " + of_word + " " + (isPagingAccurate ? "" : "~") + "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
            super.onLoad(event);
        }
    };
    pagingBar.setBrowseRecordsGridCall(true);
    pagingBar.setHideMode(HideMode.VISIBILITY);
    pagingBar.getMessages().setDisplayMsg(MessagesFactory.getMessages().page_displaying_records());

    pagingBar.setVisible(false);
    pagingBar.bind(loader);
    gridContainer.setBottomComponent(pagingBar);
    grid = new ColumnAlignGrid<ItemBean>(store, cm);
    grid.setSelectionModel(sm);

    {
        grid.setStateful(true);
        AppHeader header = (AppHeader) BrowseRecords.getSession().get(UserSession.APP_HEADER);
        ViewBean vb = (ViewBean) BrowseRecords.getSession().get(UserSession.CURRENT_VIEW);
        EntityModel em = vb.getBindingEntityModel();
        grid.setStateId(header.getDatamodel() + "." + em.getConceptName() + "." + vb.getViewPK()); //$NON-NLS-1$//$NON-NLS-2$
    }

    re = new SaveRowEditor();
    if (cm.getColumnCount() > 0) {
        grid.setAutoExpandColumn(cm.getColumn(0).getHeader());
    }

    grid.addListener(Events.HeaderClick, new Listener<GridEvent<?>>() {

        @Override
        public void handleEvent(GridEvent<?> be) {
            if (be.getColIndex() == 0) {
                ItemsListPanel.this.isCheckbox = true;
            } else {
                ItemsListPanel.this.isCheckbox = false;
            }
        }

    });

    grid.addListener(Events.OnMouseOver, new Listener<GridEvent<ItemBean>>() {

        @Override
        public void handleEvent(GridEvent<ItemBean> ge) {
            int rowIndex = ge.getRowIndex();
            if (rowIndex != -1) {
                if (ge.getColIndex() == 0) {
                    ItemsListPanel.this.isCheckbox = true;
                } else {
                    ItemsListPanel.this.isCheckbox = false;
                }

                ItemBean item = grid.getStore().getAt(rowIndex);
                grid.getView().getRow(item).getStyle().setCursor(Style.Cursor.POINTER);
            }
        }
    });

    grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ItemBean>() {

        @Override
        public void selectionChanged(final SelectionChangedEvent<ItemBean> se) {
            if (se.getSelectedItem() != null) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        if (isCurrentRecordChange()) {
                            MessageBox msgBox = MessageBox.confirm(
                                    MessagesFactory.getMessages().confirm_title(),
                                    MessagesFactory.getMessages().msg_confirm_save_tree_detail(root.getLabel()),
                                    new Listener<MessageBoxEvent>() {

                                        @Override
                                        public void handleEvent(MessageBoxEvent be) {
                                            if (Dialog.YES.equals(be.getButtonClicked().getItemId())) {
                                                saveCurrentChangeBeforeSwitching = true;
                                                changedRecordId = toolBar.getItemBean().getIds();
                                                toolBar.saveItemAndClose(true);
                                            }
                                            selectRow(se);
                                        }
                                    });
                            msgBox.getDialog().setWidth(550);
                        } else {
                            selectRow(se);
                        }

                    }
                });
            }

        }
    });

    grid.addListener(Events.Attach, new Listener<GridEvent<ItemBean>>() {

        @Override
        public void handleEvent(GridEvent<ItemBean> be) {
            PagingLoadConfig config = new BasePagingLoadConfig();
            config.setOffset(0);
            int pageSize = pagingBar.getPageSize();
            config.setLimit(pageSize);
            loader.load(config);
            pagingBar.setVisible(true);
        }
    });

    grid.setLoadMask(true);
    grid.setBorders(false);
    grid.setAutoExpandMin(120);
    grid.setAutoExpandColumn(columnConfigList.get(1).getId());
    grid.addPlugin(re);
    grid.addPlugin(sm);
    grid.getAriaSupport().setDescribedBy("abcdefg"); //$NON-NLS-1$
    grid.getAriaSupport().setLabelledBy(this.getHeader().getId() + "-label"); //$NON-NLS-1$

    gridContainer.add(grid);
    gridContainer.setFrame(false);
    gridContainer.setHeight(this.getHeight() - ItemsToolBar.getInstance().getHeight()
            - ItemsToolBar.getInstance().getAdvancedPanel().getHeight());
    hookContextMenu();

    re.addListener(Events.AfterEdit, new Listener<RowEditorEvent>() {

        @Override
        public void handleEvent(RowEditorEvent be) {
            Map<String, Object> changes = be.getChanges();
            Iterator<String> iterator = changes.keySet().iterator();
            Map<String, String> changedField = new HashMap<String, String>(changes.size());

            EntityModel entityModel = (EntityModel) BrowseRecords.getSession()
                    .get(UserSession.CURRENT_ENTITY_MODEL);
            final ItemBean itemBean = grid.getSelectionModel().getSelectedItem();
            Map<String, Object> originalMap = itemBean.getOriginalMap();

            while (iterator.hasNext()) {
                String path = iterator.next();
                TypeModel tm = entityModel.getMetaDataTypes().get(path);
                String value;
                if (tm.getForeignkey() != null) {
                    if (changes.get(path) == null) {
                        value = ""; //$NON-NLS-1$
                    } else {
                        value = changes.get(path).toString();
                    }
                    ForeignKeyBean fkBean = itemBean.getForeignkeyDesc(value);
                    if (fkBean != null) {
                        changedField.put(path, fkBean.getId());
                    } else {
                        changedField.put(path, ""); //$NON-NLS-1$
                    }
                } else {
                    if (changes.get(path) == null) {
                        continue;
                    }
                    value = changes.get(path).toString();
                    if (originalMap.containsKey(path)) {
                        Object data = originalMap.get(path);
                        if (DataTypeConstants.DATE.getTypeName().equals(tm.getType().getBaseTypeName())) {
                            value = DateUtil.getDate((Date) data);
                        } else if (DataTypeConstants.DATETIME.getTypeName()
                                .equals(tm.getType().getBaseTypeName())) {
                            value = DateUtil.getDateTime((Date) data);
                        } else {
                            value = String.valueOf(data);
                        }
                    }
                    changedField.put(path, value != null ? value : ""); //$NON-NLS-1$                        
                }
            }

            ItemsDetailPanel detailPanel = ItemsMainTabPanel.getInstance().getDefaultViewTabItem();

            Widget widget = detailPanel.getFirstTabWidget();

            ItemNodeModel model = null;
            if (widget instanceof ItemPanel) {// save primary key
                ItemPanel itemPanel = (ItemPanel) widget;
                model = itemPanel.getTree().getRootModel();
            } else if (widget instanceof ForeignKeyTreeDetail) { // save foreign key
                ForeignKeyTreeDetail fkDetail = (ForeignKeyTreeDetail) widget;
                model = fkDetail.getRootModel();
            }
            ViewBean viewBean = (ViewBean) BrowseRecords.getSession().get(UserSession.CURRENT_VIEW);
            String xml = (new ItemTreeHandler(model, viewBean, ItemTreeHandlingStatus.ToSave)).serializeItem();

            service.updateItem(itemBean.getConcept(), itemBean.getIds(), changedField, xml, entityModel,
                    Locale.getLanguage(), new SessionAwareAsyncCallback<ItemResult>() {

                        @Override
                        protected void doOnFailure(Throwable caught) {
                            Record record;
                            Store<ItemBean> store = grid.getStore();
                            if (store != null) {
                                record = store.getRecord(itemBean);
                            } else {
                                record = null;
                            }

                            if (record != null) {
                                record.reject(false);
                            }

                            String err = caught.getLocalizedMessage();
                            if (err != null) {
                                MessageBox.alert(MessagesFactory.getMessages().error_title(),
                                        MultilanguageMessageParser.pickOutISOMessage(err), null);
                            } else {
                                super.doOnFailure(caught);
                            }
                        }

                        @Override
                        public void onSuccess(ItemResult result) {
                            Record record;
                            Store<ItemBean> store = grid.getStore();
                            if (store != null) {
                                record = store.getRecord(itemBean);
                            } else {
                                record = null;
                            }

                            if (record != null) {
                                record.commit(false);
                            }
                            final MessageBox msgBox = new MessageBox();
                            String msg = MultilanguageMessageParser.pickOutISOMessage(result.getDescription());
                            if (result.getStatus() == ItemResult.FAILURE) {
                                msgBox.setTitle(MessagesFactory.getMessages().error_title());
                                msgBox.setButtons(MessageBox.OK);
                                msgBox.setIcon(MessageBox.ERROR);
                                msgBox.setMessage(msg == null || msg.isEmpty()
                                        ? MessagesFactory.getMessages().output_report_null()
                                        : msg);
                                msgBox.addCallback(new Listener<MessageBoxEvent>() {

                                    @Override
                                    public void handleEvent(MessageBoxEvent be) {
                                        refreshOnSaveCompleted(itemBean);
                                    }
                                });
                                msgBox.show();
                            } else {
                                msgBox.setTitle(MessagesFactory.getMessages().info_title());
                                msgBox.setButtons(""); //$NON-NLS-1$
                                msgBox.setIcon(MessageBox.INFO);
                                msgBox.setMessage(msg == null || msg.isEmpty()
                                        ? MessagesFactory.getMessages().save_success()
                                        : msg);
                                msgBox.show();
                                Timer timer = new Timer() {

                                    public void run() {
                                        msgBox.close();
                                        refreshOnSaveCompleted(itemBean);
                                    }
                                };
                                timer.schedule(1000);
                            }
                        }
                    });
        }

    });

    add(gridContainer);
    this.syncSize();
    this.doLayout();
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.LineageListPanel.java

License:Open Source License

private ContentPanel generateGrid() {
    gridContainer = new ContentPanel(new FitLayout());

    Button taskButton = new Button();
    taskButton = new Button(MessagesFactory.getMessages().open_task());
    taskButton.setId("openTaskButton"); //$NON-NLS-1$
    taskButton.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.openTask()));

    taskButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override// w  w  w.  j  a  va  2  s  .c  o  m
        public void componentSelected(ButtonEvent buttonEvent) {
            initDSC(LineageListPanel.this.taskId);
        }
    });
    openTaskToolBar = new ToolBar();
    openTaskToolBar.add(taskButton);
    gridContainer.setTopComponent(openTaskToolBar);

    ColumnModel cm = new ColumnModel(generateColumnList());
    gridContainer.setBodyBorder(false);
    gridContainer.setHeaderVisible(false);

    loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
    loader.setRemoteSort(true);

    store = new ListStore<ItemBean>(loader);
    store.setKeyProvider(keyProvidernew);

    loader.addLoadListener(new LoadListener() {

        @Override
        public void loaderLoad(LoadEvent le) {
            if (store.getModels().size() > 0) {
                grid.getSelectionModel().select(0, false);
            }
        }
    });

    int usePageSize = Constants.PAGE_SIZE;
    if (Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE) != null) {
        usePageSize = Integer.parseInt(Cookies.getCookie(PagingToolBarEx.BROWSERECORD_PAGESIZE));
    }

    pagingBar = new PagingToolBarEx(usePageSize) {

        @Override
        protected void onLoad(LoadEvent event) {
            String of_word = MessagesFactory.getMessages().of_word();
            msgs.setDisplayMsg("{0} - {1} " + of_word + " " + (isPagingAccurate ? "" : "~") + "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
            super.onLoad(event);
        }
    };
    pagingBar.setBrowseRecordsGridCall(true);
    pagingBar.setHideMode(HideMode.VISIBILITY);
    pagingBar.getMessages().setDisplayMsg(MessagesFactory.getMessages().page_displaying_records());

    pagingBar.setVisible(false);
    pagingBar.bind(loader);
    gridContainer.setBottomComponent(pagingBar);
    grid = new ColumnAlignGrid<ItemBean>(store, cm);

    {
        grid.setStateful(true);
        AppHeader header = (AppHeader) BrowseRecords.getSession().get(UserSession.APP_HEADER);
        ViewBean vb = (ViewBean) BrowseRecords.getSession().get(UserSession.CURRENT_VIEW);
        grid.setStateId(header.getDatamodel() + "." + entityModel.getConceptName() + "." + vb.getViewPK()); //$NON-NLS-1$//$NON-NLS-2$
    }

    grid.getView().setForceFit(true);
    if (cm.getColumnCount() > 0) {
        grid.setAutoExpandColumn(cm.getColumn(0).getHeader());
    }

    grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ItemBean>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<ItemBean> se) {
            selectRow(se.getSelectedItem());
        }
    });

    grid.setLoadMask(true);

    grid.getAriaSupport().setDescribedBy("abcdefg"); //$NON-NLS-1$
    grid.getAriaSupport().setLabelledBy(this.getHeader().getId() + "-label"); //$NON-NLS-1$

    grid.addPlugin(filters);
    gridContainer.add(grid);

    return gridContainer;
}

From source file:org.talend.mdm.webapp.browserecords.client.widget.NavigatorPanel.java

License:Open Source License

private void initPanel() {
    setHeaderVisible(false);/*w  w w  .  j a v a 2s  . c  o m*/
    setLayout(new BorderLayout());
    setStyleAttribute("height", "100%"); //$NON-NLS-1$ //$NON-NLS-2$  
    BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 800);
    westData.setMargins(new Margins(0, 5, 0, 0));
    westData.setSplit(true);
    westData.setFloatable(false);
    westData.setMinSize(0);
    westData.setMaxSize(7000);
    initNavigatorPanel();
    add(navigatorPanel, westData);

    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
    initDetailPanel();
    add(detailPanel, centerData);

    if (Cookies.getCookie(NAVIGATOR_PAGESIZE) != null) {
        pageSize = Integer.parseInt(Cookies.getCookie(NAVIGATOR_PAGESIZE));
    }

    settingWindow = new Window();
    settingWindow.setHeading(MessagesFactory.getMessages().setting_window_title());
    settingWindow.setWidth(300);
    settingWindow.setHeight(131);
    settingWindow.setResizable(false);
    settingWindow.setDraggable(false);
    settingWindow.setLayout(new FitLayout());
    settingWindow.setModal(true);
    settingWindow.setBlinkModal(true);

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    TableData layoutData = new TableData();
    layoutData.setPadding(10);
    Label pageSizeLabel = new Label(MessagesFactory.getMessages().page_size_field_label());
    final NumberField pageSizeField = new NumberField();
    pageSizeField.setValue(pageSize);
    pageSizeField.setValidator(validator);
    pageSizeField.setWidth(150);
    horizontalPanel.add(pageSizeLabel, layoutData);
    horizontalPanel.add(pageSizeField, layoutData);
    Button okButton = new Button(MessagesFactory.getMessages().ok_btn());
    okButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (pageSizeField.isValid()) {
                NavigatorPanel.this.pageSize = pageSizeField.getValue().intValue();
                Cookies.setCookie(NAVIGATOR_PAGESIZE, String.valueOf(NavigatorPanel.this.pageSize));
                settingWindow.close();
            }
        }
    });
    Button cancelButton = new Button(MessagesFactory.getMessages().cancel_btn());
    cancelButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            pageSizeField.setValue(pageSize);
            settingWindow.close();
        }
    });
    settingWindow.add(horizontalPanel);
    settingWindow.setButtonAlign(HorizontalAlignment.CENTER);
    settingWindow.addButton(okButton);
    settingWindow.addButton(cancelButton);
}

From source file:org.talend.mdm.webapp.general.client.layout.BorderLayoutContainer.java

License:Open Source License

@Override
protected void onRender(Element target, int index) {
    super.onRender(target, index);
    final BorderLayout layout = new BorderLayout();
    setLayout(layout);/*from  w ww  .  j a  v  a 2s .  c o  m*/
    this.setBorders(false);

    ContentPanel north = BrandingBar.getInstance();
    AccordionMenus west = AccordionMenus.getInstance();
    west.addListener(Events.Resize, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            Cookies.setCookie(WEST_WIDTH, AccordionMenus.getInstance().getWidth() + ""); //$NON-NLS-1$
        }
    });
    WorkSpace center = WorkSpace.getInstance();
    center.setId("MDMCenterWorkspace"); //$NON-NLS-1$
    center.setBorders(false);

    ActionsPanel east = ActionsPanel.getInstance();
    east.addListener(Events.Resize, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            Cookies.setCookie(EAST_WIDTH, ActionsPanel.getInstance().getWidth() + ""); //$NON-NLS-1$
        }
    });
    east.setBorders(false);

    BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH, 40);
    northData.setCollapsible(false);
    northData.setFloatable(false);
    northData.setHideCollapseTool(true);

    BorderLayoutData westData;
    String westWidth = Cookies.getCookie(WEST_WIDTH);
    if (westWidth != null && westWidth.trim().length() > 0) {
        westData = new BorderLayoutData(LayoutRegion.WEST, Integer.parseInt(westWidth));
    } else {
        westData = new BorderLayoutData(LayoutRegion.WEST, DEFAULT_WEST_SIZE);
    }

    westData.setMaxSize(300);
    westData.setSplit(true);
    westData.setCollapsible(true);
    westData.setFloatable(true);
    westData.setMargins(new Margins(0, 5, 0, 0));

    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
    centerData.setMargins(new Margins(0));

    BorderLayoutData eastData;
    String eastWidth = Cookies.getCookie(EAST_WIDTH);
    if (eastWidth != null && eastWidth.trim().length() > 0) {
        eastData = new BorderLayoutData(LayoutRegion.EAST, Integer.parseInt(eastWidth));
    } else {
        eastData = new BorderLayoutData(LayoutRegion.EAST, DEFAULT_EAST_SIZE);
    }

    eastData.setMaxSize(300);
    eastData.setSplit(true);
    eastData.setCollapsible(true);
    eastData.setFloatable(false);
    eastData.setMargins(new Margins(0, 0, 0, 5));

    add(north, northData);
    add(west, westData);
    add(center, centerData);
    add(east, eastData);
    registerWorkingMessage();
    this.setId("MDMGeneral"); //$NON-NLS-1$
    this.getElement().getStyle().setPosition(Position.ABSOLUTE);
    this.getElement().getStyle().setTop(0D, Unit.PX);
    this.getElement().getStyle().setLeft(0D, Unit.PX);
}

From source file:org.testmp.webconsole.client.WebConsole.java

License:Open Source License

/**
 * This is called when the browser loads Application.html.
 *///w  ww  . j a  v a2s .co  m
public void onModuleLoad() {
    GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
        public void onUncaughtException(Throwable t) {
            System.err.println("--- UNCAUGHT EXCEPTION ---");
            t.printStackTrace();
        }
    });

    prepareDataSources();

    VLayout vLayout = new VLayout();
    vLayout.setMargin(5);
    vLayout.setLayoutMargin(5);
    vLayout.setAlign(Alignment.CENTER);
    vLayout.setSize("100%", "100%");

    HLayout header = new HLayout();
    header.setWidth("95%");
    header.setHeight(72);
    header.setMembersMargin(5);
    header.setLayoutAlign(Alignment.CENTER);

    Label logo = new Label();
    logo.setIcon("testmp-logo.png");
    logo.setIconWidth(265);
    logo.setIconHeight(82);
    logo.setWidth("95%");
    logo.setValign(VerticalAlignment.TOP);
    logo.setLayoutAlign(Alignment.CENTER);
    header.addMember(logo);

    ClientConfig.currentUser = Cookies.getCookie(ClientConfig.constants.currentUserCookie());
    if (ClientConfig.currentUser == null) {
        loginBtn = new IconButton(ClientConfig.messages.login());
    } else {
        loginBtn = new IconButton(ClientConfig.messages.hi() + ", " + ClientConfig.currentUser);
    }
    loginBtn.setIcon("person.png");
    loginBtn.setLayoutAlign(VerticalAlignment.TOP);
    loginBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            LoginWindow window = new LoginWindow();
            window.show();
        }

    });
    header.addMember(loginBtn);

    settingBtn = new IconButton(ClientConfig.messages.settings());
    settingBtn.setIcon("setting.png");
    settingBtn.setLayoutAlign(VerticalAlignment.TOP);
    settingBtn.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (ClientConfig.currentUser != null) {
                SettingWindow window = new SettingWindow();
                window.show();
            } else {
                SC.say(ClientConfig.messages.nullUser());
            }
        }

    });
    header.addMember(settingBtn);

    vLayout.addMember(header);

    TabSet appTabSet = new TabSet();
    appTabSet.setTabBarPosition(Side.TOP);
    appTabSet.setTabBarAlign(Side.RIGHT);
    appTabSet.setWidth("95%");
    appTabSet.setLayoutAlign(Alignment.CENTER);
    vLayout.addMember(appTabSet);

    String copyright = "<span style=\"font-family:Arial;\">&copy;</span>2013 Zhaowei Ding";
    String licenseLink = "http://opensource.org/licenses/MIT";
    String license = "Licensed under the <a href='" + licenseLink + "'>the MIT License</a>.";

    HTMLFlow footer = new HTMLFlow(copyright + ", " + license);
    footer.setWidth100();
    footer.setHeight(10);
    footer.setStyleName("footing");
    footer.setMargin(5);
    vLayout.addMember(footer);

    Tab welcomeTab = new Tab(ClientConfig.messages.welcome());
    welcomeTab.setName("welcomeTab");
    welcomeTab.setIcon("welcome.png");
    welcomeTab.setWidth(120);
    welcomeTab.setPane(new MainPageView());
    appTabSet.addTab(welcomeTab);

    Tab testCaseTab = new Tab(ClientConfig.messages.testCase());
    testCaseTab.setName("testCaseTab");
    testCaseTab.setWidth(120);
    testCaseTab.setPane(new TestCaseView());
    appTabSet.addTab(testCaseTab);

    Tab testDataTab = new Tab(ClientConfig.messages.testData());
    testDataTab.setName("testDataTab");
    testDataTab.setWidth(120);
    testDataTab.setPane(new TestDataView());
    appTabSet.addTab(testDataTab);

    Tab testEnvTab = new Tab(ClientConfig.messages.testEnvironment());
    testEnvTab.setName("testEnvTab");
    testEnvTab.setWidth(120);
    testEnvTab.setPane(new TestEnvView());
    appTabSet.addTab(testEnvTab);

    vLayout.draw();
}