Example usage for com.vaadin.ui Alignment MIDDLE_CENTER

List of usage examples for com.vaadin.ui Alignment MIDDLE_CENTER

Introduction

In this page you can find the example usage for com.vaadin.ui Alignment MIDDLE_CENTER.

Prototype

Alignment MIDDLE_CENTER

To view the source code for com.vaadin.ui Alignment MIDDLE_CENTER.

Click Source Link

Usage

From source file:de.symeda.sormas.ui.dashboard.statistics.DashboardStatisticsCountGrowthElement.java

License:Open Source License

public DashboardStatisticsCountGrowthElement(String caption, CountElementStyle countElementStyle) {
    super(caption);
    addStyleName("count-element");
    addStyleName(countElementStyle.getCssClass());

    setComponentAlignment(captionLabel, Alignment.MIDDLE_CENTER);
    setComponentAlignment(growthLayout, Alignment.MIDDLE_CENTER);
}

From source file:de.symeda.sormas.ui.dashboard.statistics.DashboardStatisticsGrowthElement.java

License:Open Source License

public DashboardStatisticsGrowthElement(String caption, String captionClass, Alignment alignment) {
    this.setMargin(false);
    this.setSpacing(false);

    this.caption = caption;
    this.captionClass = captionClass;

    if (alignment != null) {
        setDefaultComponentAlignment(alignment);
    }//from www . jav  a2 s . c o m
    CssStyles.style(this, CssStyles.VSPACE_3);

    growthLayout = new HorizontalLayout();

    createCountLabel();
    growthLayout.addComponent(countLabel);
    createGrowthLabel();
    growthLayout.addComponent(growthLabel);
    growthLayout.setComponentAlignment(growthLabel, Alignment.MIDDLE_CENTER);
    createPercentageLabel();
    growthLayout.addComponent(percentageLabel);

    addComponent(growthLayout);

    createCaptionLabel();
    addComponent(captionLabel);
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseTileComponent.java

License:Open Source License

void addTopLayout(Disease disease, Long casesCount, boolean isOutbreak) {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setMargin(false);//from   ww  w  . j a  v a 2s  . co  m
    layout.setSpacing(false);
    CssStyles.style(layout, CssStyles.getDiseaseColor(disease));
    layout.setHeight(75, Unit.PIXELS);
    layout.setWidth(100, Unit.PERCENTAGE);

    VerticalLayout nameAndOutbreakLayout = new VerticalLayout();
    nameAndOutbreakLayout.setMargin(false);
    nameAndOutbreakLayout.setSpacing(false);
    nameAndOutbreakLayout.setHeight(100, Unit.PERCENTAGE);
    nameAndOutbreakLayout.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setMargin(false);
    nameLayout.setSpacing(false);
    nameLayout.setWidth(100, Unit.PERCENTAGE);
    nameLayout.setHeight(100, Unit.PERCENTAGE);
    Label nameLabel = new Label(disease.toShortString());
    CssStyles.style(nameLabel, CssStyles.LABEL_WHITE,
            nameLabel.getValue().length() > 12 ? CssStyles.LABEL_LARGE : CssStyles.LABEL_XLARGE,
            CssStyles.LABEL_BOLD, CssStyles.ALIGN_CENTER, CssStyles.LABEL_UPPERCASE);
    nameLayout.addComponent(nameLabel);
    nameLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_CENTER);
    nameAndOutbreakLayout.addComponent(nameLayout);
    nameAndOutbreakLayout.setExpandRatio(nameLayout, 1);

    if (isOutbreak) {
        HorizontalLayout outbreakLayout = new HorizontalLayout();
        outbreakLayout.setMargin(false);
        outbreakLayout.setSpacing(false);
        CssStyles.style(outbreakLayout, CssStyles.BACKGROUND_CRITICAL);
        outbreakLayout.setWidth(100, Unit.PERCENTAGE);
        outbreakLayout.setHeight(30, Unit.PIXELS);
        Label outbreakLabel = new Label(I18nProperties.getCaption(Captions.dashboardOutbreak));
        CssStyles.style(outbreakLabel, CssStyles.LABEL_WHITE, CssStyles.ALIGN_CENTER,
                CssStyles.LABEL_UPPERCASE);
        outbreakLayout.addComponent(outbreakLabel);
        outbreakLayout.setComponentAlignment(outbreakLabel, Alignment.MIDDLE_CENTER);
        nameAndOutbreakLayout.addComponent(outbreakLayout);
    }

    layout.addComponent(nameAndOutbreakLayout);
    layout.setExpandRatio(nameAndOutbreakLayout, 1);

    HorizontalLayout countLayout = new HorizontalLayout();
    countLayout.setMargin(false);
    countLayout.setSpacing(false);
    CssStyles.style(countLayout, CssStyles.getDiseaseColor(disease), CssStyles.BACKGROUND_DARKER);
    countLayout.setHeight(100, Unit.PERCENTAGE);
    countLayout.setWidth(100, Unit.PERCENTAGE);

    Label countLabel = new Label(casesCount.toString());
    CssStyles.style(countLabel, CssStyles.LABEL_WHITE, CssStyles.LABEL_BOLD, CssStyles.LABEL_XXXLARGE,
            CssStyles.ALIGN_CENTER);
    countLayout.addComponent(countLabel);
    countLayout.setComponentAlignment(countLabel, Alignment.MIDDLE_CENTER);

    layout.addComponent(countLayout);
    layout.setExpandRatio(countLayout, 0.65f);

    addComponent(layout);
}

From source file:de.unioninvestment.eai.portal.portlet.crud.export.ExportDialog.java

License:Apache License

@SuppressWarnings("serial")
private void init() {
    setCaption(Context.getMessage("portlet.crud.dialog.export.title"));
    setModal(true);//from  w ww .  j  a v  a  2  s.  c o m
    setResizable(false);
    setWidth("400px");
    addCloseListener(new CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            handleWindowCloseEvent();
        }
    });

    indicator = new ProgressBar(0.0f);
    indicator.setWidth("100%");
    UI.getCurrent().setPollInterval(1000);

    if (automaticDownload) {
        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.addComponent(indicator);

        setContent(layout);
    } else {
        HorizontalLayout layout = new HorizontalLayout();
        layout.setWidth("100%");
        layout.setMargin(true);
        layout.setSpacing(true);

        downloadLink = new Link();
        downloadLink.setStyleName(LiferayTheme.BUTTON_LINK);
        downloadLink.setCaption(Context.getMessage("portlet.crud.dialog.export.download"));
        downloadLink.setEnabled(false);

        layout.addComponents(indicator, downloadLink);
        layout.setComponentAlignment(indicator, Alignment.MIDDLE_CENTER);
        layout.setComponentAlignment(downloadLink, Alignment.MIDDLE_CENTER);
        layout.setExpandRatio(indicator, 1f);

        setContent(layout);
    }

}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultCompoundSearchView.java

License:Apache License

@Override
public void initialize(TableColumns fields) {
    this.fields = fields;
    searchBox = new SearchBox(this);
    searchBox.setWidth("100%");
    searchBox.setOptionHandler(new SearchOptionsHandler(fields));
    searchBox.focus();//from  ww w.j a v a2  s  .  co m
    searchBox.setInputPrompt(getMessage("portlet.crud.compoundsearch.inputPrompt"));

    Button resetButton = new Button(getMessage("portlet.crud.compoundsearch.reset"));
    resetButton.setStyleName(LiferayTheme.BUTTON_LINK);
    resetButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            presenter.reset();
        }
    });

    PopupView infoButton = new PopupView(new Content() {
        @Override
        public String getMinimizedValueAsHTML() {
            return "?";
        }

        @Override
        public Component getPopupComponent() {
            return createSearchInfo();
        }
    });
    infoButton.setHideOnMouseOut(false);

    searchBar = new HorizontalLayout(searchBox, resetButton, infoButton);
    searchBar.setWidth("100%");
    searchBar.addStyleName("compsearchbar");
    searchBar.setExpandRatio(searchBox, 1);
    searchBar.setSpacing(true);
    searchBar.setComponentAlignment(resetButton, Alignment.MIDDLE_CENTER);
    searchBar.setComponentAlignment(infoButton, Alignment.MIDDLE_CENTER);

    addComponent(searchBar);
}

From source file:de.unioninvestment.portal.explorer.view.vfs.ConfigView.java

License:Apache License

public ConfigView(ConfigBean cb, VFSFileExplorerPortlet instance) {

    final OptionGroup group = new OptionGroup("Type");
    group.addItem("FILE");
    group.addItem("FTP");
    group.addItem("SFTP");
    group.setValue(cb.getVfsType());/*  w  w w. ja  va2  s  .  c o m*/
    group.setImmediate(true);

    final TextField tfDirectory = new TextField("Directory");
    tfDirectory.setValue(cb.getVfsUrl());

    final TextField tfKeyFile = new TextField("Keyfile");
    tfKeyFile.setValue(cb.getKeyfile());

    final TextField tfProxyHost = new TextField("Proxy Host (sftp)");
    tfProxyHost.setValue(cb.getProxyHost());

    final TextField tfProxyPort = new TextField("Proxy Port (sftp)");
    tfProxyPort.setValue(cb.getProxyPort());

    final TextField tfUser = new TextField("User");
    tfUser.setValue(cb.getUsername());

    final PasswordField tfPw = new PasswordField("Password");
    tfPw.setValue(cb.getPassword());

    final CheckBox cbUploadEnabled = new CheckBox("Upload Enabled");
    if (cb.isUploadEnabled()) {
        cbUploadEnabled.setValue(true);
    } else
        cbUploadEnabled.setValue(false);

    final TextField tfRolesUpload = new TextField("Upload Rollen");
    tfRolesUpload.setValue(cb.getUploadRoles());

    final CheckBox cbDeleteEnabled = new CheckBox("Delete Enabled");
    if (cb.isDeleteEnabled()) {
        cbDeleteEnabled.setValue(true);
    } else
        cbDeleteEnabled.setValue(false);

    final TextField tfRolesDelete = new TextField("Delete Rollen");
    tfRolesDelete.setValue(cb.getDeleteRoles());

    group.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            setVisibleFields(group, tfKeyFile, tfProxyHost, tfProxyPort, tfUser, tfPw);

        }

    });

    setVisibleFields(group, tfKeyFile, tfProxyHost, tfProxyPort, tfUser, tfPw);

    Button saveProps = new Button("Save");
    final VFSFileExplorerPortlet app = instance;
    saveProps.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                PortletPreferences prefs = app.getPortletPreferences();

                String type = group.getValue().toString();
                prefs.setValue("type", type);

                String con = tfDirectory.getValue().toString();
                prefs.setValue("directory", con);

                String key = tfKeyFile.getValue().toString();
                prefs.setValue("keyfile", key);

                String proxyHost = tfProxyHost.getValue().toString();
                prefs.setValue("proxyHost", proxyHost);

                String proxyPort = tfProxyPort.getValue().toString();
                prefs.setValue("proxyPort", proxyPort);

                String uploadRoles = tfRolesUpload.getValue().toString();
                prefs.setValue("uploadRoles", uploadRoles);

                String deleteRoles = tfRolesDelete.getValue().toString();
                prefs.setValue("deleteRoles", deleteRoles);

                String username = tfUser.getValue().toString();
                prefs.setValue("username", username);

                String password = tfPw.getValue().toString();
                prefs.setValue("password", password);

                Boolean bDel = (Boolean) cbDeleteEnabled.getValue();
                Boolean bUpl = (Boolean) cbUploadEnabled.getValue();
                if (bDel)
                    prefs.setValue("deleteEnabled", "true");
                else
                    prefs.setValue("deleteEnabled", "false");

                if (bUpl)
                    prefs.setValue("uploadEnabled", "true");
                else
                    prefs.setValue("uploadEnabled", "false");

                prefs.store();

                logger.log(Level.INFO, "Roles Upload " + prefs.getValue("uploadEnabled", "-"));
                logger.log(Level.INFO, "Roles Delete " + prefs.getValue("deleteEnabled", "-"));

                ConfigBean cb = new ConfigBean(type, bDel, false, bUpl, con, username, password, key, proxyHost,
                        proxyPort, uploadRoles, deleteRoles);

                app.getEventBus().fireEvent(new ConfigChangedEvent(cb));

            } catch (Exception e) {
                logger.log(Level.INFO, "Exception " + e.toString());
                e.printStackTrace();
            }
        }
    });
    addComponent(group);
    addComponent(tfDirectory);
    addComponent(tfKeyFile);
    addComponent(tfProxyHost);
    addComponent(tfProxyPort);
    addComponent(tfUser);
    addComponent(tfPw);

    HorizontalLayout ul = new HorizontalLayout();
    ul.setSpacing(true);
    ul.addComponent(cbUploadEnabled);
    ul.addComponent(tfRolesUpload);
    ul.setComponentAlignment(cbUploadEnabled, Alignment.MIDDLE_CENTER);
    ul.setComponentAlignment(tfRolesUpload, Alignment.MIDDLE_CENTER);
    addComponent(ul);

    HorizontalLayout dl = new HorizontalLayout();
    dl.setSpacing(true);
    dl.addComponent(cbDeleteEnabled);
    dl.addComponent(tfRolesDelete);
    dl.setComponentAlignment(cbDeleteEnabled, Alignment.MIDDLE_CENTER);
    dl.setComponentAlignment(tfRolesDelete, Alignment.MIDDLE_CENTER);
    addComponent(dl);
    addComponent(saveProps);
}

From source file:de.unioninvestment.portal.explorer.view.vfs.TableView.java

License:Apache License

public void attach() {

    selectedDir = cb.getVfsUrl();/*from w  ww  . j  a va  2s . co m*/
    try {

        final VFSFileExplorerPortlet app = instance;
        final User user = (User) app.getUser();
        final FileSystemManager fFileSystemManager = fileSystemManager;
        final FileSystemOptions fOpts = opts;

        final Table table = new Table() {

            private static final long serialVersionUID = 1L;

            protected String formatPropertyValue(Object rowId, Object colId, Property property) {

                if (TABLE_PROP_FILE_NAME.equals(colId)) {
                    if (property != null && property.getValue() != null) {
                        return getDisplayPath(property.getValue().toString());
                    }
                }
                if (TABLE_PROP_FILE_DATE.equals(colId)) {
                    if (property != null && property.getValue() != null) {
                        SimpleDateFormat sdf = new SimpleDateFormat("dd.MMM yyyy HH:mm:ss");
                        return sdf.format((Date) property.getValue());
                    }
                }
                return super.formatPropertyValue(rowId, colId, property);
            }

        };
        table.setSizeFull();
        table.setMultiSelect(true);
        table.setSelectable(true);
        table.setImmediate(true);
        table.addContainerProperty(TABLE_PROP_FILE_NAME, String.class, null);
        table.addContainerProperty(TABLE_PROP_FILE_SIZE, Long.class, null);
        table.addContainerProperty(TABLE_PROP_FILE_DATE, Date.class, null);
        if (app != null) {
            app.getEventBus().addHandler(TableChangedEvent.class, new TableChangedEventHandler() {
                private static final long serialVersionUID = 1L;

                @Override
                public void onValueChanged(TableChangedEvent event) {
                    try {
                        selectedDir = event.getNewDirectory();
                        fillTableData(event.getNewDirectory(), table, fFileSystemManager, fOpts, null);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        table.addListener(new Table.ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            public void valueChange(ValueChangeEvent event) {

                Set<?> value = (Set<?>) event.getProperty().getValue();
                if (null == value || value.size() == 0) {
                    markedRows = null;
                } else {
                    markedRows = value;
                }
            }
        });

        fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);

        Button btDownload = new Button("Download File(s)");
        btDownload.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            public void buttonClick(ClickEvent event) {
                if (markedRows == null || markedRows.size() == 0)
                    getWindow().showNotification("No Files selected !",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                else {
                    String[] files = new String[markedRows.size()];
                    int fileCount = 0;

                    for (Object item : markedRows) {
                        Item it = table.getItem(item);
                        files[fileCount] = it.getItemProperty(TABLE_PROP_FILE_NAME).toString();
                        fileCount++;
                    }

                    File dlFile = null;
                    if (fileCount == 1) {
                        try {
                            String fileName = files[0];
                            dlFile = getFileFromVFSObject(fFileSystemManager, fOpts, fileName);
                            logger.log(Level.INFO,
                                    "vfs2portlet: download file " + fileName + " by " + user.getScreenName());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        byte[] buf = new byte[1024];

                        try {
                            dlFile = File.createTempFile("Files", ".zip");
                            ZipOutputStream out = new ZipOutputStream(
                                    new FileOutputStream(dlFile.getAbsolutePath()));
                            for (int i = 0; i < files.length; i++) {
                                String fileName = files[i];
                                logger.log(Level.INFO, "vfs2portlet: download file " + fileName + " by "
                                        + user.getScreenName());
                                File f = getFileFromVFSObject(fFileSystemManager, fOpts, fileName);
                                FileInputStream in = new FileInputStream(f);
                                out.putNextEntry(new ZipEntry(f.getName()));
                                int len;
                                while ((len = in.read(buf)) > 0) {
                                    out.write(buf, 0, len);
                                }
                                out.closeEntry();
                                in.close();
                            }
                            out.close();
                        } catch (IOException e) {
                        }

                    }

                    if (dlFile != null) {
                        try {
                            DownloadResource downloadResource = new DownloadResource(dlFile, getApplication());
                            getApplication().getMainWindow().open(downloadResource, "_new");
                        } catch (FileNotFoundException e) {
                            getWindow().showNotification("File not found !",
                                    Window.Notification.TYPE_ERROR_MESSAGE);
                            e.printStackTrace();
                        }

                    }

                    if (dlFile != null) {
                        dlFile.delete();
                    }
                }

            }
        });

        Button btDelete = new Button("Delete File(s)");
        btDelete.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            public void buttonClick(ClickEvent event) {

                if (markedRows == null || markedRows.size() == 0)
                    getWindow().showNotification("No Files selected !",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                else {
                    for (Object item : markedRows) {
                        Item it = table.getItem(item);
                        String fileToDelete = it.getItemProperty(TABLE_PROP_FILE_NAME).toString();
                        logger.log(Level.INFO, "Delete File " + fileToDelete);
                        try {
                            FileObject delFile = fFileSystemManager.resolveFile(fileToDelete, fOpts);
                            logger.log(Level.INFO, "vfs2portlet: delete file " + delFile.getName() + " by "
                                    + user.getScreenName());
                            boolean b = delFile.delete();
                            if (b)
                                logger.log(Level.INFO, "delete ok");
                            else
                                logger.log(Level.INFO, "delete failed");
                        } catch (FileSystemException e) {
                            e.printStackTrace();
                        }
                    }
                    try {
                        fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            }
        });

        Button selAll = new Button("Select All", new Button.ClickListener() {

            private static final long serialVersionUID = 1L;

            public void buttonClick(Button.ClickEvent event) {
                table.setValue(table.getItemIds());
            }
        });

        Button selNone = new Button("Select None", new Button.ClickListener() {

            private static final long serialVersionUID = 1L;

            public void buttonClick(Button.ClickEvent event) {
                table.setValue(null);
            }
        });

        final UploadReceiver receiver = new UploadReceiver();
        upload = new Upload(null, receiver);
        upload.setImmediate(true);
        upload.setButtonCaption("File Upload");

        upload.addListener((new Upload.SucceededListener() {

            private static final long serialVersionUID = 1L;

            public void uploadSucceeded(SucceededEvent event) {

                try {
                    String fileName = receiver.getFileName();
                    ByteArrayOutputStream bos = receiver.getUploadedFile();
                    byte[] buf = bos.toByteArray();
                    ByteArrayInputStream bis = new ByteArrayInputStream(buf);
                    String fileToAdd = selectedDir + "/" + fileName;
                    logger.log(Level.INFO,
                            "vfs2portlet: add file " + fileToAdd + " by " + user.getScreenName());
                    FileObject localFile = fFileSystemManager.resolveFile(fileToAdd, fOpts);
                    localFile.createFile();
                    OutputStream localOutputStream = localFile.getContent().getOutputStream();
                    IOUtils.copy(bis, localOutputStream);
                    localOutputStream.flush();
                    fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);
                    app.getMainWindow().showNotification("Upload " + fileName + " successful ! ",
                            Notification.TYPE_TRAY_NOTIFICATION);

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }));

        upload.addListener(new Upload.FailedListener() {
            private static final long serialVersionUID = 1L;

            public void uploadFailed(FailedEvent event) {
                System.out.println("Upload failed ! ");
            }
        });

        multiFileUpload = new MultiFileUpload() {

            private static final long serialVersionUID = 1L;

            protected void handleFile(File file, String fileName, String mimeType, long length) {
                try {
                    byte[] buf = FileUtils.readFileToByteArray(file);
                    ByteArrayInputStream bis = new ByteArrayInputStream(buf);
                    String fileToAdd = selectedDir + "/" + fileName;
                    logger.log(Level.INFO,
                            "vfs2portlet: add file " + fileToAdd + " by " + user.getScreenName());
                    FileObject localFile = fFileSystemManager.resolveFile(fileToAdd, fOpts);
                    localFile.createFile();
                    OutputStream localOutputStream = localFile.getContent().getOutputStream();
                    IOUtils.copy(bis, localOutputStream);
                    localOutputStream.flush();
                    fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);
                } catch (FileSystemException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            protected FileBuffer createReceiver() {
                FileBuffer receiver = super.createReceiver();
                /*
                 * Make receiver not to delete files after they have been
                 * handled by #handleFile().
                 */
                receiver.setDeleteFiles(false);
                return receiver;
            }
        };
        multiFileUpload.setUploadButtonCaption("Upload File(s)");

        HorizontalLayout filterGrp = new HorizontalLayout();
        filterGrp.setSpacing(true);
        final TextField tfFilter = new TextField();
        Button btFileFilter = new Button("Filter", new Button.ClickListener() {

            private static final long serialVersionUID = 1L;

            public void buttonClick(Button.ClickEvent event) {
                String filterVal = (String) tfFilter.getValue();
                try {
                    if (filterVal == null || filterVal.length() == 0) {
                        fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);
                    } else {
                        fillTableData(selectedDir, table, fFileSystemManager, fOpts, filterVal);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        Button btResetFileFilter = new Button("Reset", new Button.ClickListener() {

            private static final long serialVersionUID = 1L;

            public void buttonClick(Button.ClickEvent event) {
                try {
                    tfFilter.setValue("");
                    fillTableData(selectedDir, table, fFileSystemManager, fOpts, null);
                } catch (ReadOnlyException e) {
                    e.printStackTrace();
                } catch (ConversionException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        filterGrp.addComponent(tfFilter);
        filterGrp.addComponent(btFileFilter);
        filterGrp.addComponent(btResetFileFilter);

        addComponent(filterGrp);

        addComponent(table);

        HorizontalLayout btGrp = new HorizontalLayout();

        btGrp.setSpacing(true);
        btGrp.addComponent(selAll);
        btGrp.setComponentAlignment(selAll, Alignment.MIDDLE_CENTER);
        btGrp.addComponent(selNone);
        btGrp.setComponentAlignment(selNone, Alignment.MIDDLE_CENTER);
        btGrp.addComponent(btDownload);
        btGrp.setComponentAlignment(btDownload, Alignment.MIDDLE_CENTER);

        List<Role> roles = null;
        boolean matchUserRole = false;
        try {

            if (user != null) {
                roles = user.getRoles();

            }
        } catch (SystemException e) {
            e.printStackTrace();
        }

        if (cb.isDeleteEnabled() && cb.getDeleteRoles().length() == 0) {
            btGrp.addComponent(btDelete);
            btGrp.setComponentAlignment(btDelete, Alignment.MIDDLE_CENTER);
        } else if (cb.isDeleteEnabled() && cb.getDeleteRoles().length() > 0) {
            matchUserRole = isUserInRole(roles, cb.getDeleteRoles());
            if (matchUserRole) {
                btGrp.addComponent(btDelete);
                btGrp.setComponentAlignment(btDelete, Alignment.MIDDLE_CENTER);
            }

        }
        if (cb.isUploadEnabled() && cb.getUploadRoles().length() == 0) {
            btGrp.addComponent(upload);
            btGrp.setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
            btGrp.addComponent(multiFileUpload);
            btGrp.setComponentAlignment(multiFileUpload, Alignment.MIDDLE_CENTER);
        } else if (cb.isUploadEnabled() && cb.getUploadRoles().length() > 0) {

            matchUserRole = isUserInRole(roles, cb.getUploadRoles());
            if (matchUserRole) {
                btGrp.addComponent(upload);
                btGrp.setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
                btGrp.addComponent(multiFileUpload);
                btGrp.setComponentAlignment(multiFileUpload, Alignment.MIDDLE_CENTER);
            }
        }
        addComponent(btGrp);

    } catch (SocketException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:de.uni_leipzig.informatik.pcai042.boa.gui.goldstandard.GoldstandardGUI.java

License:Open Source License

/**
 * The constructor should first build the main layout, set the composition
 * root and then do any custom initialization.
 * /*from  w  w w.ja  v a2 s. co m*/
 * The constructor will not be automatically regenerated by the visual
 * editor.
 */
public GoldstandardGUI() {
    buildMainLayout();
    setCompositionRoot(mainLayout);

    // user code

    for (Type t : BoaAnnotation.Type.values()) {
        comboBoxTypes.addItem(t);
    }
    comboBoxTypes.setTextInputAllowed(false);
    listSelectAnnotations.setMultiSelect(false);
    comboBoxTypes.setNullSelectionAllowed(false);
    listSelectAnnotations.setNullSelectionAllowed(false);

    // with this layout components will get wrapped
    cssLayoutTokens = new CssLayout() {
        @Override
        protected String getCss(Component c) {
            return "float:left;margin-right:5px;";
        }
    };
    cssLayoutTokens.setWidth("100%");
    // auto; becomes vertical scroll-able since verticalLayout_tokens height
    // is also auto
    cssLayoutTokens.setHeight(SIZE_UNDEFINED, 0);
    verticalLayoutTokens.addComponent(cssLayoutTokens);

    resetComponents();

    buttonNext.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            if (sentence != null) {
                SentenceServer.returnSentence(sentence);
            }

            resetComponents();
            sentence = SentenceServer.getSentence();

            if (sentence == null) {
                getWindow().showNotification("No more senentences.", Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            // create new check boxes for tokens
            CheckBox checkbox;
            Label label;
            VerticalLayout vertLayout;
            for (int i = 0; i < sentence.getTokens().size(); i++) {
                checkbox = new CheckBox();
                checkbox.setImmediate(true);
                checkbox.addListener(new Property.ValueChangeListener() {
                    public void valueChange(ValueChangeEvent event) {
                        Iterator<Component> iterator = cssLayoutTokens.getComponentIterator();
                        Label l;
                        CheckBox cb;
                        VerticalLayout vl;
                        String s = "";
                        while (iterator.hasNext()) {
                            vl = (VerticalLayout) iterator.next();
                            l = (Label) vl.getComponent(0);
                            cb = (CheckBox) vl.getComponent(1);
                            if (cb.booleanValue()) {
                                s += l.getValue();
                            }
                        }
                        if (s.isEmpty())
                            s = "";
                        textFieldLabel.setReadOnly(false);
                        textFieldLabel.setValue(s);
                        textFieldLabel.setReadOnly(true);
                    }
                });
                label = new Label(sentence.getTokens().get(i));
                label.setSizeUndefined();
                vertLayout = new VerticalLayout();
                vertLayout.addComponent(label);
                vertLayout.addComponent(checkbox);
                vertLayout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
                vertLayout.setComponentAlignment(checkbox, Alignment.MIDDLE_CENTER);
                vertLayout.setSizeUndefined();
                cssLayoutTokens.addComponent(vertLayout);
            }
        }
    });

    buttonDiscard.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            if (sentence != null) {
                SentenceServer.discardSentence(sentence);
                resetComponents();
            }
        }
    });

    buttonAddAnno.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            if (!textFieldLabel.getValue().equals("") && comboBoxTypes.getValue() != null) {
                Iterator<Component> iterator = cssLayoutTokens.getComponentIterator();
                Label l;
                CheckBox cb;
                VerticalLayout vl;
                ArrayList<String> selected = new ArrayList<String>();
                while (iterator.hasNext()) {
                    vl = (VerticalLayout) iterator.next();
                    l = (Label) vl.getComponent(0);
                    cb = (CheckBox) vl.getComponent(1);
                    if (cb.booleanValue()) {
                        selected.add((String) l.getValue());
                        cb.setValue(false);
                    }
                }
                BoaAnnotation anno = new BoaAnnotation((Type) comboBoxTypes.getValue(), selected);
                boolean isDuplicate = false;
                boolean isColliding = false;
                for (BoaAnnotation a : sentence.getAnnotations()) {
                    if (a.getTokens().size() == anno.getTokens().size()) {
                        boolean sameTokens = true;
                        for (int i = 0; i < a.getTokens().size(); i++) {
                            sameTokens = a.getTokens().get(i) == anno.getTokens().get(i);
                            if (!sameTokens)
                                break;
                        }
                        if (sameTokens) {
                            isColliding = !(isDuplicate = a.getType().equals(anno.getType()));
                            break;
                        }
                    }
                }
                if (isDuplicate) {
                    getWindow().showNotification("Duplicate was dismissed.", Notification.TYPE_WARNING_MESSAGE);
                } else if (isColliding) {
                    getWindow().showNotification("Label is already assigned to<br/> a different type.",
                            Notification.TYPE_ERROR_MESSAGE);
                } else {
                    sentence.getAnnotations().add(anno);
                    listSelectAnnotations.addItem(anno);
                }
            } else
                getWindow().showNotification("Label or type is inavlid.", Notification.TYPE_ERROR_MESSAGE);
        }
    });

    buttonDelAnno.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            if (listSelectAnnotations.getValue() != null) {
                sentence.getAnnotations().remove(listSelectAnnotations.getValue());
                listSelectAnnotations.removeItem(listSelectAnnotations.getValue());
            }
        }
    });
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.HomeView.java

License:Open Source License

/**
 * sets the ContainerDataSource of this view. Should usually contain project information. Caption
 * is caption.//from  w  w  w.j  a va  2  s . c om
 * 
 * @param homeViewInformation
 * @param caption
 */
public void setContainerDataSource(SpaceBean spaceBean, String newCaption) {

    caption = newCaption;
    currentBean = spaceBean;
    numberOfProjects = currentBean.getProjects().size();
    projectGrid = new Grid();

    GeneratedPropertyContainer gpcProjects = new GeneratedPropertyContainer(spaceBean.getProjects());
    gpcProjects.removeContainerProperty("members");
    gpcProjects.removeContainerProperty("id");
    gpcProjects.removeContainerProperty("experiments");
    gpcProjects.removeContainerProperty("contact");
    gpcProjects.removeContainerProperty("contactPerson");
    gpcProjects.removeContainerProperty("projectManager");
    gpcProjects.removeContainerProperty("containsData");
    gpcProjects.removeContainerProperty("containsResults");
    gpcProjects.removeContainerProperty("containsAttachments");
    gpcProjects.removeContainerProperty("description");
    gpcProjects.removeContainerProperty("progress");
    gpcProjects.removeContainerProperty("registrationDate");
    gpcProjects.removeContainerProperty("registrator");
    gpcProjects.removeContainerProperty("longDescription");

    projectGrid.setContainerDataSource(gpcProjects);

    projectGrid.setHeightMode(HeightMode.ROW);
    projectGrid.setHeightByRows(20);

    // projectGrid.getColumn("space").setWidthUndefined();
    // projectGrid.getColumn("code").setWidthUndefined();
    // projectGrid.getColumn("secondaryName").setWidthUndefined();
    // projectGrid.getColumn("principalInvestigator").setWidthUndefined();

    projectGrid.getColumn("code").setHeaderCaption("Sub-Project").setWidth(150);
    // projectGrid.getColumn("space").setWidth(200);

    Column nameCol = projectGrid.getColumn("secondaryName");
    nameCol.setHeaderCaption("Short Name");
    nameCol.setMaximumWidth(450);
    projectGrid.getColumn("space").setMaximumWidth(350);
    projectGrid.getColumn("space").setHeaderCaption("Project");
    projectGrid.getColumn("principalInvestigator").setHeaderCaption("Investigator");
    projectGrid.setColumnOrder("code", "space", "secondaryName", "principalInvestigator");

    projectGrid.setResponsive(true);

    helpers.GridFunctions.addColumnFilters(projectGrid, gpcProjects);

    gpcProjects.addGeneratedProperty("Summary", new PropertyValueGenerator<String>() {
        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "show";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    projectGrid.getColumn("Summary").setWidthUndefined();

    projectGrid.getColumn("Summary").setRenderer(new ButtonRenderer(new RendererClickListener() {

        @Override
        public void click(RendererClickEvent event) {
            // Show loading window
            ProgressBar bar = new ProgressBar();
            bar.setIndeterminate(true);
            VerticalLayout vl = new VerticalLayout(bar);
            vl.setComponentAlignment(bar, Alignment.MIDDLE_CENTER);
            vl.setWidth("50%");
            vl.setSpacing(true);
            vl.setMargin(true);

            Window loadingWindow = new Window("Loading project summary...");
            loadingWindow.setWidth("50%");
            loadingWindow.setContent(vl);
            loadingWindow.center();
            loadingWindow.setModal(true);
            loadingWindow.setResizable(false);
            QbicmainportletUI ui = (QbicmainportletUI) UI.getCurrent();
            ui.addWindow(loadingWindow);

            // fetch summary and create docx in tmp folder

            ProjectBean proj = (ProjectBean) event.getItemId();
            summaryFetcher.fetchSummaryComponent(proj.getCode(), proj.getSecondaryName(), proj.getDescription(),
                    new ProjectSummaryReadyRunnable(summaryFetcher, loadingWindow, proj.getCode()));
        }
    }));
    projectGrid.getColumn("Summary").setWidth(100);

    projectGrid.addSelectionListener(new SelectionListener() {

        @Override
        public void select(SelectionEvent event) {
            Set<Object> selectedElements = event.getSelected();
            if (selectedElements == null) {
                return;
            }

            ProjectBean selectedProject = (ProjectBean) selectedElements.iterator().next();

            if (selectedProject == null) {
                return;
            }

            String entity = selectedProject.getId();
            State state = (State) UI.getCurrent().getSession().getAttribute("state");
            ArrayList<String> message = new ArrayList<String>();
            message.add("clicked");
            message.add(entity);
            message.add(ProjectView.navigateToLabel);
            state.notifyObservers(message);
        }
    });
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.HomeView.java

License:Open Source License

@Override
public void enter(ViewChangeEvent event) {
    try {/*  w w w.j av  a  2  s .  c o  m*/
        loadProjects();
        int height = event.getNavigator().getUI().getPage().getBrowserWindowHeight();
        int width = event.getNavigator().getUI().getPage().getBrowserWindowWidth();
        buildLayout(height, width, event.getNavigator().getUI().getPage().getWebBrowser());
    } catch (Exception e) {
        LOGGER.error(String.format("failed to load projects for user %s", user), e);
        // homeview_content.removeAllComponents();
        removeAllComponents();
        Label error = new Label("Connection to database interrupted. Please try again later.");
        error.addStyleName(ValoTheme.LABEL_FAILURE);
        error.addStyleName(ValoTheme.LABEL_HUGE);
        addComponent(error);
        setComponentAlignment(error, Alignment.MIDDLE_CENTER);

        // homeview_content.addComponent(error);
        // homeview_content.setComponentAlignment(error, Alignment.MIDDLE_CENTER);
        // this.addComponent(homeview_content);
    }
}