List of usage examples for com.vaadin.ui ComboBox ComboBox
public ComboBox()
From source file:org.apache.openaz.xacml.admin.view.windows.ExpressionEditorWindow.java
License:Apache License
@AutoGenerated private VerticalLayout buildMainLayout() { // common part: create layout mainLayout = new VerticalLayout(); mainLayout.setImmediate(false);//from www . j a v a2 s .co m mainLayout.setWidth("-1px"); mainLayout.setHeight("-1px"); mainLayout.setMargin(true); mainLayout.setSpacing(true); // top-level component properties setWidth("-1px"); setHeight("-1px"); // comboBox comboBox = new ComboBox(); comboBox.setImmediate(false); comboBox.setWidth("-1px"); comboBox.setHeight("-1px"); mainLayout.addComponent(comboBox); // treeExpression treeExpression = new Tree(); treeExpression.setImmediate(false); treeExpression.setWidth("100.0%"); treeExpression.setHeight("-1px"); mainLayout.addComponent(treeExpression); mainLayout.setExpandRatio(treeExpression, 1.0f); return mainLayout; }
From source file:org.apache.openaz.xacml.admin.view.windows.PolicyNameEditorWindow.java
License:Apache License
@AutoGenerated private FormLayout buildMainLayout() { // common part: create layout mainLayout = new FormLayout(); mainLayout.setImmediate(false);/*from w w w. jav a2s . c o m*/ // textFieldPolicyName textFieldPolicyName = new TextField(); textFieldPolicyName.setCaption("Policy File Name"); textFieldPolicyName.setImmediate(true); textFieldPolicyName.setWidth("-1px"); textFieldPolicyName.setHeight("-1px"); textFieldPolicyName.setInputPrompt("Enter filename eg. foobar.xml"); textFieldPolicyName.setRequired(true); mainLayout.addComponent(textFieldPolicyName); // textAreaDescription textAreaDescription = new TextArea(); textAreaDescription.setCaption("Description"); textAreaDescription.setImmediate(false); textAreaDescription.setWidth("100%"); textAreaDescription.setHeight("-1px"); textAreaDescription.setInputPrompt("Enter a description for the Policy/PolicySet."); textAreaDescription.setNullSettingAllowed(true); mainLayout.addComponent(textAreaDescription); // optionPolicySet optionPolicySet = new OptionGroup(); optionPolicySet.setCaption("Policy or PolicySet?"); optionPolicySet.setImmediate(true); optionPolicySet.setDescription("Is the root level a Policy or Policy Set."); optionPolicySet.setWidth("-1px"); optionPolicySet.setHeight("-1px"); optionPolicySet.setRequired(true); mainLayout.addComponent(optionPolicySet); // comboAlgorithms comboAlgorithms = new ComboBox(); comboAlgorithms.setCaption("Combining Algorithm"); comboAlgorithms.setImmediate(false); comboAlgorithms.setDescription("Select the combining algorithm."); comboAlgorithms.setWidth("-1px"); comboAlgorithms.setHeight("-1px"); comboAlgorithms.setRequired(true); mainLayout.addComponent(comboAlgorithms); // buttonSave buttonSave = new Button(); buttonSave.setCaption("Save"); buttonSave.setImmediate(true); buttonSave.setWidth("-1px"); buttonSave.setHeight("-1px"); mainLayout.addComponent(buttonSave); mainLayout.setComponentAlignment(buttonSave, new Alignment(48)); return mainLayout; }
From source file:org.asi.ui.pagedtable.PagedTable.java
License:Apache License
public HorizontalLayout createControls(PagedControlConfig config) { Label itemsPerPageLabel = new Label(config.getItemsPerPage(), ContentMode.HTML); itemsPerPageLabel.setSizeUndefined(); final ComboBox itemsPerPageSelect = new ComboBox(); for (Integer i : config.getPageLengths()) { itemsPerPageSelect.addItem(i);//from w w w . jav a 2s .c o m itemsPerPageSelect.setItemCaption(i, String.valueOf(i)); } itemsPerPageSelect.setImmediate(true); itemsPerPageSelect.setNullSelectionAllowed(false); itemsPerPageSelect.setWidth(null); itemsPerPageSelect.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -2255853716069800092L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { setPageLength((Integer) event.getProperty().getValue()); } }); if (itemsPerPageSelect.containsId(getPageLength())) { itemsPerPageSelect.select(getPageLength()); } else { itemsPerPageSelect.select(itemsPerPageSelect.getItemIds().iterator().next()); } Label pageLabel = new Label(config.getPage(), ContentMode.HTML); final TextField currentPageTextField = new TextField(); currentPageTextField.setValue(String.valueOf(getCurrentPage())); currentPageTextField.setConverter(new StringToIntegerConverter() { @Override protected NumberFormat getFormat(Locale locale) { NumberFormat result = super.getFormat(UI.getCurrent().getLocale()); result.setGroupingUsed(false); return result; } }); Label separatorLabel = new Label(" / ", ContentMode.HTML); final Label totalPagesLabel = new Label(String.valueOf(getTotalAmountOfPages()), ContentMode.HTML); currentPageTextField.setStyleName(Reindeer.TEXTFIELD_SMALL); currentPageTextField.setImmediate(true); currentPageTextField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -2255853716069800092L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { if (currentPageTextField.isValid() && currentPageTextField.getValue() != null) { int page = Integer.valueOf(String.valueOf(currentPageTextField.getValue())); setCurrentPage(page); } } }); pageLabel.setWidth(null); currentPageTextField.setColumns(3); separatorLabel.setWidth(null); totalPagesLabel.setWidth(null); HorizontalLayout controlBar = new HorizontalLayout(); HorizontalLayout pageSize = new HorizontalLayout(); HorizontalLayout pageManagement = new HorizontalLayout(); final Button first = new Button(config.getFirst(), new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { setCurrentPage(0); } }); final Button previous = new Button(config.getPrevious(), new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { previousPage(); } }); final Button next = new Button(config.getNext(), new Button.ClickListener() { private static final long serialVersionUID = -1927138212640638452L; @Override public void buttonClick(Button.ClickEvent event) { nextPage(); } }); final Button last = new Button(config.getLast(), new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { setCurrentPage(getTotalAmountOfPages()); } }); first.setStyleName(Reindeer.BUTTON_LINK); previous.setStyleName(Reindeer.BUTTON_LINK); next.setStyleName(Reindeer.BUTTON_LINK); last.setStyleName(Reindeer.BUTTON_LINK); itemsPerPageLabel.addStyleName("pagedtable-itemsperpagecaption"); itemsPerPageSelect.addStyleName("pagedtable-itemsperpagecombobox"); pageLabel.addStyleName("pagedtable-pagecaption"); currentPageTextField.addStyleName("pagedtable-pagefield"); separatorLabel.addStyleName("pagedtable-separator"); totalPagesLabel.addStyleName("pagedtable-total"); first.addStyleName("pagedtable-first"); previous.addStyleName("pagedtable-previous"); next.addStyleName("pagedtable-next"); last.addStyleName("pagedtable-last"); itemsPerPageLabel.addStyleName("pagedtable-label"); itemsPerPageSelect.addStyleName("pagedtable-combobox"); pageLabel.addStyleName("pagedtable-label"); currentPageTextField.addStyleName("pagedtable-label"); separatorLabel.addStyleName("pagedtable-label"); totalPagesLabel.addStyleName("pagedtable-label"); first.addStyleName("pagedtable-button"); previous.addStyleName("pagedtable-button"); next.addStyleName("pagedtable-button"); last.addStyleName("pagedtable-button"); pageSize.addComponent(itemsPerPageLabel); pageSize.addComponent(itemsPerPageSelect); pageSize.setComponentAlignment(itemsPerPageLabel, Alignment.MIDDLE_LEFT); pageSize.setComponentAlignment(itemsPerPageSelect, Alignment.MIDDLE_LEFT); pageSize.setSpacing(true); pageManagement.addComponent(first); pageManagement.addComponent(previous); pageManagement.addComponent(pageLabel); pageManagement.addComponent(currentPageTextField); pageManagement.addComponent(separatorLabel); pageManagement.addComponent(totalPagesLabel); pageManagement.addComponent(next); pageManagement.addComponent(last); pageManagement.setComponentAlignment(first, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(previous, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(pageLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(currentPageTextField, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(separatorLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(totalPagesLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(next, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(last, Alignment.MIDDLE_LEFT); pageManagement.setWidth(null); pageManagement.setSpacing(true); controlBar.addComponent(pageSize); controlBar.addComponent(pageManagement); controlBar.setComponentAlignment(pageManagement, Alignment.MIDDLE_CENTER); controlBar.setWidth(100, Sizeable.Unit.PERCENTAGE); controlBar.setExpandRatio(pageSize, 1); if (container != null) { first.setEnabled(container.getStartIndex() > 0); previous.setEnabled(container.getStartIndex() > 0); next.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); last.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); } addListener(new PageChangeListener() { private boolean inMiddleOfValueChange; @Override public void pageChanged(PagedTableChangeEvent event) { if (!inMiddleOfValueChange) { inMiddleOfValueChange = true; first.setEnabled(container.getStartIndex() > 0); previous.setEnabled(container.getStartIndex() > 0); next.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); last.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); currentPageTextField.setValue(String.valueOf(getCurrentPage())); totalPagesLabel.setValue(Integer.toString(getTotalAmountOfPages())); itemsPerPageSelect.setValue(getPageLength()); inMiddleOfValueChange = false; } } }); return controlBar; }
From source file:org.eclipse.emf.ecp.controls.vaadin.internal.EnumComboViewerVaadinRenderer.java
License:Open Source License
@Override public Component createControl() { final Setting setting = getVElement().getDomainModelReference().getIterator().next(); final IItemLabelProvider labelProvider = getItemPropertyDescriptor(setting).getLabelProvider(null); final ComboBox combobox = new ComboBox() { @Override/*from w w w. j a va2 s . c o m*/ public String getItemCaption(Object itemId) { return labelProvider.getText(itemId); } }; combobox.setItemCaptionMode(ItemCaptionMode.ITEM); final List<Object> inputValues = new ArrayList<Object>(); for (final EEnumLiteral literal : EEnum.class.cast(setting.getEStructuralFeature().getEType()) .getELiterals()) { inputValues.add(literal.getInstance()); } combobox.setInvalidAllowed(false); combobox.setNullSelectionAllowed(false); combobox.addItems(inputValues); return combobox; }
From source file:org.eclipse.hawkbit.ui.decorators.SPUIComboBoxDecorator.java
License:Open Source License
/** * Decorate.//from ww w .ja v a2 s . c o m * * @param caption * caption of the combobox * @param height * as H * @param width * as W * @param style * as style * @param styleName * as style name * @param required * as T|F * @param data * as data * @param prompt * as promt * @return ComboBox as comp */ public static ComboBox decorate(final String caption, final String width, final String style, final String styleName, final boolean required, final String data, final String prompt) { final ComboBox spUICombo = new ComboBox(); // Default settings spUICombo.setRequired(required); spUICombo.addStyleName(ValoTheme.COMBOBOX_TINY); if (!StringUtils.isEmpty(caption)) { spUICombo.setCaption(caption); } // Add style if (!StringUtils.isEmpty(style)) { spUICombo.setStyleName(style); } // Add style Name if (!StringUtils.isEmpty(styleName)) { spUICombo.addStyleName(styleName); } // AddWidth if (!StringUtils.isEmpty(width)) { spUICombo.setWidth(width); } // Set prompt if (!StringUtils.isEmpty(prompt)) { spUICombo.setInputPrompt(prompt); } // Set Data if (!StringUtils.isEmpty(data)) { spUICombo.setData(data); } return spUICombo; }
From source file:org.eclipse.hawkbit.ui.management.footer.MaintenanceWindowLayout.java
License:Open Source License
/** * Combo box to pick the time zone offset. *//*from w ww . j a v a2 s. c om*/ private void createMaintenanceTimeZoneControl() { // ComboBoxBuilder cannot be used here, because Builder do // 'comboBox.setItemCaptionPropertyId(SPUILabelDefinitions.VAR_NAME);' // which interferes our code: 'timeZone.addItems(getAllTimeZones());' timeZone = new ComboBox(); timeZone.setId(UIComponentIdProvider.MAINTENANCE_WINDOW_TIME_ZONE_ID); timeZone.setCaption(i18n.getMessage("caption.maintenancewindow.timezone")); timeZone.addItems(getAllTimeZones()); timeZone.setValue(getClientTimeZone()); timeZone.addStyleName(ValoTheme.COMBOBOX_SMALL); timeZone.setTextInputAllowed(false); timeZone.setNullSelectionAllowed(false); }
From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.TagComponent.java
License:Open Source License
@SuppressWarnings("serial") private void paintTagComboBoxLayout() { tagComboBoxLayout.removeAllComponents(); // add tag input field final ComboBox tagComboBox = new ComboBox(); SortedMap<String, Integer> availableTags = taggingService.getTags(Project.class); for (String tag : availableTags.keySet()) { tagComboBox.addItem(tag);/*from www. ja v a 2s . c o m*/ } tagComboBox.setNewItemsAllowed(true); tagComboBox.setNewItemHandler(new NewItemHandler() { @Override public void addNewItem(String newItemCaption) { Collection<Validator> validators = tagComboBox.getValidators(); for (Validator val : validators) { if (!val.isValid(newItemCaption)) { Iterator<Component> it = tagComboBoxLayout.getComponentIterator(); it.next(); // this is the combobox if (!it.hasNext()) { tagComboBoxLayout .addComponent(new Label("Use lowercase letters without whitespaces only.")); } return; } } if (!tagComboBox.containsId(newItemCaption)) { TaggingUtils.addTags(project, newItemCaption); util.persist(project); paintTagEdit(); // TODO performance? } } }); tagComboBox.addListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if (!TaggingUtils.hasTag(project, event.getProperty().getValue().toString())) { TaggingUtils.addTags(project, event.getProperty().getValue().toString()); util.persist(project); paintTagEdit(); // TODO performance? } } }); tagComboBox.setImmediate(true); tagComboBox.setInputPrompt("Enter tag confirmed by enter"); tagComboBox.setWidth("300px"); tagComboBox.setNullSelectionAllowed(false); tagComboBox.focus(); tagComboBox.addValidator(new TagValidator()); tagComboBoxLayout.addComponent(tagComboBox); }
From source file:org.escidoc.browser.ui.maincontent.ContainerView.java
License:Open Source License
private void handleLayoutListeners() { if (hasAccess()) { vlPropertiesLeft.addListener(new LayoutClickListener() { private static final long serialVersionUID = 1L; @Override//from w w w . j a va 2 s . c om public void layoutClick(final LayoutClickEvent event) { // Get the child component which was clicked if (event.getChildComponent() != null) { // Is Label? if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") { final Label child = (Label) event.getChildComponent(); if ((child.getDescription() == ViewConstants.DESC_STATUS) && (!lblStatus.getValue().equals(status + "withdrawn"))) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editStatus(child.getValue().toString().replace(status, "")); vlPropertiesLeft.replaceComponent(oldComponent, swapComponent); } else if (child.getDescription() == ViewConstants.DESC_LOCKSTATUS) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editLockStatus(child.getValue().toString().replace(status, "")); vlPropertiesLeft.replaceComponent(oldComponent, swapComponent); } } // else { // // getWindow().showNotification( // // "The click was over a " + // event.getChildComponent().getClass().getCanonicalName() // // + event.getChildComponent().getStyleName()); // } } else { reSwapComponents(); } } /** * Switch the component back to the original component (Label) after inline editing */ private void reSwapComponents() { if (swapComponent != null) { if (swapComponent instanceof Label) { ((Label) oldComponent).setValue(((TextArea) swapComponent).getValue()); } else if ((swapComponent instanceof ComboBox) && ((ComboBox) swapComponent).getValue() != null) { ((Label) oldComponent).setValue(status + ((ComboBox) swapComponent).getValue()); // Because there should be no comment-window on // Delete Operation if (!(((ComboBox) swapComponent).getValue().equals("delete"))) { addCommentWindow(); } else { updateContainer(""); } } vlPropertiesLeft.replaceComponent(swapComponent, oldComponent); swapComponent = null; } } private Component editLockStatus(final String lockStatus) { final ComboBox cmbLockStatus = new ComboBox(); cmbLockStatus.setNullSelectionAllowed(false); if (lockStatus.contains("unlocked")) { cmbLockStatus.addItem(LockStatus.LOCKED.toString().toLowerCase()); } else { cmbLockStatus.addItem(LockStatus.UNLOCKED.toString().toLowerCase()); } cmbLockStatus.select(1); return cmbLockStatus; } private Component editStatus(final String publicStatus) { final ComboBox cmbStatus = new ComboBox(); cmbStatus.setInvalidAllowed(false); cmbStatus.setNullSelectionAllowed(false); final String pubStatus = publicStatus.toUpperCase(); if (publicStatus.equals("pending")) { cmbStatus.addItem(PublicStatus.PENDING.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.setNullSelectionItemId(PublicStatus.PENDING.toString().toLowerCase()); if (hasAccessDelResource()) { cmbStatus.addItem("delete"); } } else if (publicStatus.equals("submitted")) { cmbStatus.setNullSelectionItemId(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase()); } else if (publicStatus.equals("in_revision")) { cmbStatus.setNullSelectionItemId(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); } else if (publicStatus.equals("released")) { cmbStatus.setNullSelectionItemId(PublicStatus.RELEASED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.WITHDRAWN.toString().toLowerCase()); } else if (publicStatus.equals("withdrawn")) { // do nothing } else { cmbStatus.addItem(PublicStatus.valueOf(pubStatus)); } cmbStatus.select(1); return cmbStatus; } private boolean hasAccessDelResource() { try { return repositories.pdp().forCurrentUser().isAction(ActionIdConstants.DELETE_CONTAINER) .forResource(resourceProxy.getId()).permitted(); } catch (UnsupportedOperationException e) { mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } catch (EscidocClientException e) { mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } catch (URISyntaxException e) { mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } } public void addCommentWindow() { subwindow = new Window(ViewConstants.SUBWINDOW_EDIT); subwindow.setModal(true); // Configure the windws layout; by default a VerticalLayout VerticalLayout layout = (VerticalLayout) subwindow.getContent(); layout.setMargin(true); layout.setSpacing(true); layout.setSizeUndefined(); final TextArea editor = new TextArea("Your Comment"); editor.setRequired(true); editor.setRequiredError("The Field may not be empty."); HorizontalLayout hl = new HorizontalLayout(); Button close = new Button("Update", new Button.ClickListener() { // inline click-listener @Override public void buttonClick(ClickEvent event) { // close the window by removing it from the // parent window updateContainer(editor.getValue().toString()); (subwindow.getParent()).removeWindow(subwindow); } }); Button cancel = new Button("Cancel", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { (subwindow.getParent()).removeWindow(subwindow); } }); hl.addComponent(close); hl.addComponent(cancel); subwindow.addComponent(editor); subwindow.addComponent(hl); mainWindow.addWindow(subwindow); } private void updatePublicStatus(Container container, String comment) { // Update PublicStatus if there is a change if (!resourceProxy.getVersionStatus() .equals(lblCurrentVersionStatus.getValue().toString().replace(status, ""))) { String publicStatusTxt = lblCurrentVersionStatus.getValue().toString().replace(status, "") .toUpperCase(); if (publicStatusTxt.equals("DELETE")) { new ResourceDeleteConfirmation(container, repositories.container(), mainWindow); } try { repositories.container().changePublicStatus(container, lblCurrentVersionStatus.getValue().toString().replace(status, "").toUpperCase(), comment); if (publicStatusTxt.equals("SUBMITTED")) { mainWindow.showNotification(new Window.Notification(ViewConstants.SUBMITTED, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("IN_REVISION")) { mainWindow.showNotification(new Window.Notification(ViewConstants.IN_REVISION, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("RELEASED")) { mainWindow.showNotification(new Window.Notification(ViewConstants.RELEASED, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("WITHDRAWN")) { mainWindow.showNotification(new Window.Notification(ViewConstants.WITHDRAWN, Notification.TYPE_TRAY_NOTIFICATION)); } } catch (EscidocClientException e) { mainWindow.showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(), Notification.TYPE_ERROR_MESSAGE)); } } } private void updateLockStatus(Container container, String comment) { // Update LockStatus if there is a change if (!resourceProxy.getLockStatus() .equals(lblLockstatus.getValue().toString().replace(lockStatus, ""))) { String lockStatusTxt = lblLockstatus.getValue().toString().replace(lockStatus, "") .toUpperCase(); try { if (lockStatusTxt.contains("LOCKED")) { repositories.container().unlockResource(container, comment); mainWindow.showNotification(new Window.Notification(ViewConstants.LOCKED, Notification.TYPE_TRAY_NOTIFICATION)); } else { repositories.container().lockResource(container, comment); mainWindow.showNotification(new Window.Notification(ViewConstants.UNLOCKED, Notification.TYPE_TRAY_NOTIFICATION)); } } catch (EscidocClientException e) { mainWindow.showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(), Notification.TYPE_ERROR_MESSAGE)); } } } private void updateContainer(String comment) { LOG.debug("Called the updateContainer"); Container container; try { container = repositories.container().findContainerById(resourceProxy.getId()); if (resourceProxy.getLockStatus().contains("unlocked")) { updatePublicStatus(container, comment); // retrive the container to get the last // modifiaction date. container = repositories.container().findContainerById(resourceProxy.getId()); updateLockStatus(container, comment); } else { updateLockStatus(container, comment); updatePublicStatus(container, comment); } } catch (final EscidocClientException e) { LOG.debug("Infrastructure Exception " + e.getLocalizedMessage()); } } }); } }
From source file:org.escidoc.browser.ui.maincontent.ContextView.java
License:Open Source License
private void handleLayoutListeners() { if (contextController.canUpdateContext()) { headerLayout.addListener(new LayoutClickListener() { @Override//from ww w . j a v a 2 s .c o m public void layoutClick(final LayoutClickEvent event) { if (event.getChildComponent() != null) { // Is Label? if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") { final Label child = (Label) event.getChildComponent(); if ((child.getDescription() == ViewConstants.RESOURCE_NAME_CONTEXT)) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editName(child.getValue().toString() .replace(ViewConstants.RESOURCE_NAME_CONTEXT, ""), ViewConstants.RESOURCE_NAME_CONTEXT); headerLayout.replaceComponent(oldComponent, swapComponent); } } } else { reSwapComponents(); } } private Component editName(String name, String description) { final TextField txtType = new TextField(); txtType.setInvalidAllowed(false); txtType.setValue(name); txtType.setDescription(description); return txtType; } }); vlLeft.addListener(new LayoutClickListener() { private static final long serialVersionUID = 1L; @Override public void layoutClick(final LayoutClickEvent event) { if (event.getChildComponent() != null) { // Is Label? if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") { final Label child = (Label) event.getChildComponent(); if ((child.getDescription() == ViewConstants.CONTEXT_TYPE)) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editType( child.getValue().toString().replace(ViewConstants.CONTEXT_TYPE, ""), ViewConstants.CONTEXT_TYPE); vlLeft.replaceComponent(oldComponent, swapComponent); } else if ((child.getDescription() == ViewConstants.DESC_STATUS) && (!child.getValue() .equals(resourceProxy.getType().getLabel() + " is closed"))) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editStatus(child.getValue().toString() .replace(resourceProxy.getType().getLabel() + " is ", "")); vlLeft.replaceComponent(oldComponent, swapComponent); } } } else { reSwapComponents(); } } private ComboBox cmbStatus; private Component editStatus(final String lockStatus) { cmbStatus = new ComboBox(); cmbStatus.setNullSelectionAllowed(false); if (lockStatus.contains(CREATED)) { cmbStatus.addItem(PublicStatus.OPENED.toString().toLowerCase()); } else { cmbStatus.addItem(PublicStatus.CLOSED.toString().toLowerCase()); } cmbStatus.select(Integer.valueOf(1)); return cmbStatus; } }); } }
From source file:org.escidoc.browser.ui.maincontent.FolderView.java
License:Open Source License
private void handleLayoutListeners() { if (folderController.hasAccess()) { vlLeft.addListener(new LayoutClickListener() { private static final long serialVersionUID = 1L; private Window subwindow; @Override/*from www . ja va 2 s .c o m*/ public void layoutClick(final LayoutClickEvent event) { // Get the child component which was clicked if (event.getChildComponent() != null) { // Is Label? if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") { final Label child = (Label) event.getChildComponent(); if ((child.getDescription() == ViewConstants.DESC_STATUS) && (!lblStatus.getValue().equals(status + "withdrawn"))) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editStatus(child.getValue().toString().replace(status, "")); vlLeft.replaceComponent(oldComponent, swapComponent); } else if (child.getDescription() == ViewConstants.DESC_LOCKSTATUS) { reSwapComponents(); oldComponent = event.getClickedComponent(); swapComponent = editLockStatus(child.getValue().toString().replace(status, "")); vlLeft.replaceComponent(oldComponent, swapComponent); } } // else { // // getWindow().showNotification( // // "The click was over a " + // event.getChildComponent().getClass().getCanonicalName() // // + event.getChildComponent().getStyleName()); // } } else { reSwapComponents(); } } /** * Switch the component back to the original component (Label) after inline editing */ private void reSwapComponents() { if (swapComponent != null) { if (swapComponent instanceof Label) { ((Label) oldComponent).setValue(((TextArea) swapComponent).getValue()); } else if ((swapComponent instanceof ComboBox) && ((ComboBox) swapComponent).getValue() != null) { ((Label) oldComponent).setValue(status + ((ComboBox) swapComponent).getValue()); // Because there should be no comment-window on // Delete Operation if (!(((ComboBox) swapComponent).getValue().equals("delete"))) { addCommentWindow(); } else { updateContainer(""); } } vlLeft.replaceComponent(swapComponent, oldComponent); swapComponent = null; } } private Component editLockStatus(final String lockStatus) { final ComboBox cmbLockStatus = new ComboBox(); cmbLockStatus.setNullSelectionAllowed(false); if (lockStatus.contains("unlocked")) { cmbLockStatus.addItem(LockStatus.LOCKED.toString().toLowerCase()); } else { cmbLockStatus.addItem(LockStatus.UNLOCKED.toString().toLowerCase()); } cmbLockStatus.select(1); return cmbLockStatus; } private Component editStatus(final String publicStatus) { final ComboBox cmbStatus = new ComboBox(); cmbStatus.setInvalidAllowed(false); cmbStatus.setNullSelectionAllowed(false); final String pubStatus = publicStatus.toUpperCase(); if (publicStatus.equals("pending")) { cmbStatus.addItem(PublicStatus.PENDING.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.setNullSelectionItemId(PublicStatus.PENDING.toString().toLowerCase()); if (hasAccessDelResource()) { cmbStatus.addItem("delete"); } } else if (publicStatus.equals("submitted")) { cmbStatus.setNullSelectionItemId(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase()); } else if (publicStatus.equals("in_revision")) { cmbStatus.setNullSelectionItemId(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase()); } else if (publicStatus.equals("released")) { cmbStatus.setNullSelectionItemId(PublicStatus.RELEASED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase()); cmbStatus.addItem(PublicStatus.WITHDRAWN.toString().toLowerCase()); } else if (publicStatus.equals("withdrawn")) { // do nothing } else { cmbStatus.addItem(PublicStatus.valueOf(pubStatus)); } cmbStatus.select(1); return cmbStatus; } private boolean hasAccessDelResource() { try { return repositories.pdp().forCurrentUser().isAction(ActionIdConstants.DELETE_CONTAINER) .forResource(resourceProxy.getId()).permitted(); } catch (UnsupportedOperationException e) { router.getMainWindow().showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } catch (EscidocClientException e) { router.getMainWindow().showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } catch (URISyntaxException e) { router.getMainWindow().showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); e.printStackTrace(); return false; } } public void addCommentWindow() { subwindow = new Window(ViewConstants.SUBWINDOW_EDIT); subwindow.setModal(true); // Configure the windws layout; by default a VerticalLayout VerticalLayout layout = (VerticalLayout) subwindow.getContent(); layout.setMargin(true); layout.setSpacing(true); layout.setSizeUndefined(); final TextArea editor = new TextArea("Your Comment"); editor.setRequired(true); editor.setRequiredError("The Field may not be empty."); HorizontalLayout hl = new HorizontalLayout(); Button close = new Button("Update", new Button.ClickListener() { // inline click-listener @Override public void buttonClick(ClickEvent event) { // close the window by removing it from the // parent window updateContainer(editor.getValue().toString()); (subwindow.getParent()).removeWindow(subwindow); } }); Button cancel = new Button("Cancel", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { (subwindow.getParent()).removeWindow(subwindow); } }); hl.addComponent(close); hl.addComponent(cancel); subwindow.addComponent(editor); subwindow.addComponent(hl); router.getMainWindow().addWindow(subwindow); } private void updatePublicStatus(Container container, String comment) { // Update PublicStatus if there is a change if (!resourceProxy.getVersionStatus() .equals(lblCurrentVersionStatus.getValue().toString().replace(status, ""))) { String publicStatusTxt = lblCurrentVersionStatus.getValue().toString().replace(status, "") .toUpperCase(); if (publicStatusTxt.equals("DELETE")) { new ResourceDeleteConfirmation(container, repositories.container(), router.getMainWindow()); } try { repositories.container().changePublicStatus(container, lblCurrentVersionStatus.getValue().toString().replace(status, "").toUpperCase(), comment); if (publicStatusTxt.equals("SUBMITTED")) { router.getMainWindow().showNotification(new Window.Notification( ViewConstants.SUBMITTED, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("IN_REVISION")) { router.getMainWindow().showNotification(new Window.Notification( ViewConstants.IN_REVISION, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("RELEASED")) { router.getMainWindow().showNotification(new Window.Notification( ViewConstants.RELEASED, Notification.TYPE_TRAY_NOTIFICATION)); } else if (publicStatusTxt.equals("WITHDRAWN")) { router.getMainWindow().showNotification(new Window.Notification( ViewConstants.WITHDRAWN, Notification.TYPE_TRAY_NOTIFICATION)); } } catch (EscidocClientException e) { router.getMainWindow().showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(), Notification.TYPE_ERROR_MESSAGE)); } } } private void updateContainer(String comment) { LOG.debug("Called the updateContainer"); Container container; try { container = repositories.container().findContainerById(resourceProxy.getId()); if (resourceProxy.getLockStatus().contains("unlocked")) { container = repositories.container().findContainerById(resourceProxy.getId()); updatePublicStatus(container, comment); } else { updatePublicStatus(container, comment); } } catch (final EscidocClientException e) { LOG.debug("Infrastructure Exception " + e.getLocalizedMessage()); } } }); } }