List of usage examples for com.vaadin.ui DragAndDropWrapper DragAndDropWrapper
public DragAndDropWrapper(Component root)
From source file:org.apache.ace.webui.vaadin.AddArtifactWindow.java
License:Apache License
/** * Creates a new {@link AddArtifactWindow} instance. * /*from w ww .ja va 2s . co m*/ * @param sessionDir * the session directory to temporary place artifacts in; * @param obrUrl * the URL of the OBR to use. */ public AddArtifactWindow(File sessionDir, URL obrUrl, String repositoryXML) { super("Add artifact"); m_sessionDir = sessionDir; m_obrUrl = obrUrl; m_repositoryXML = repositoryXML; setModal(true); setWidth("50em"); setCloseShortcut(KeyCode.ESCAPE); m_artifactsTable = new Table("Artifacts in repository"); m_artifactsTable.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null); m_artifactsTable.addContainerProperty(PROPERTY_VERSION, String.class, null); m_artifactsTable.addContainerProperty(PROPERTY_PURGE, Button.class, null); m_artifactsTable.setSizeFull(); m_artifactsTable.setSelectable(true); m_artifactsTable.setMultiSelect(true); m_artifactsTable.setImmediate(true); m_artifactsTable.setHeight("15em"); final Table uploadedArtifacts = new Table("Uploaded artifacts"); uploadedArtifacts.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null); uploadedArtifacts.addContainerProperty(PROPERTY_VERSION, String.class, null); uploadedArtifacts.setSizeFull(); uploadedArtifacts.setSelectable(false); uploadedArtifacts.setMultiSelect(false); uploadedArtifacts.setImmediate(true); uploadedArtifacts.setHeight("15em"); final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) { @Override public void updateProgress(long readBytes, long contentLength) { // TODO Auto-generated method stub } @Override protected void artifactsUploaded(List<UploadHandle> uploads) { for (UploadHandle handle : uploads) { try { URL artifact = handle.getFile().toURI().toURL(); Item item = uploadedArtifacts.addItem(artifact); item.getItemProperty(PROPERTY_SYMBOLIC_NAME).setValue(handle.getFilename()); item.getItemProperty(PROPERTY_VERSION).setValue(""); m_uploadedArtifacts.add(handle.getFile()); } catch (MalformedURLException e) { showErrorNotification("Upload artifact processing failed", "<br />Reason: " + e.getMessage()); logError("Processing of " + handle.getFilename() + " failed.", e); } } } }; final Upload uploadArtifact = new Upload(); uploadArtifact.setCaption("Upload Artifact"); uploadHandler.install(uploadArtifact); final DragAndDropWrapper finalUploadedArtifacts = new DragAndDropWrapper(uploadedArtifacts); finalUploadedArtifacts.setDropHandler(new ArtifactDropHandler(uploadHandler)); addListener(new Window.CloseListener() { public void windowClose(CloseEvent e) { for (File artifact : m_uploadedArtifacts) { artifact.delete(); } } }); HorizontalLayout searchBar = new HorizontalLayout(); searchBar.setMargin(false); searchBar.setSpacing(true); final TextField searchField = new TextField(); searchField.setImmediate(true); searchField.setValue(""); final IndexedContainer dataSource = (IndexedContainer) m_artifactsTable.getContainerDataSource(); m_searchButton = new Button("Search", new ClickListener() { public void buttonClick(ClickEvent event) { String searchValue = (String) searchField.getValue(); dataSource.removeAllContainerFilters(); if (searchValue != null && searchValue.trim().length() > 0) { dataSource.addContainerFilter(PROPERTY_SYMBOLIC_NAME, searchValue, true /* ignoreCase */, false /* onlyMatchPrefix */); } } }); m_searchButton.setImmediate(true); searchBar.addComponent(searchField); searchBar.addComponent(m_searchButton); m_addButton = new Button("Add", new ClickListener() { public void buttonClick(ClickEvent event) { // Import all "local" (existing) bundles... importLocalBundles(m_artifactsTable); // Import all "remote" (non existing) bundles... importRemoteBundles(m_uploadedArtifacts); close(); } }); m_addButton.setImmediate(true); m_addButton.setStyleName(Reindeer.BUTTON_DEFAULT); m_addButton.setClickShortcut(KeyCode.ENTER); VerticalLayout layout = (VerticalLayout) getContent(); layout.setMargin(true); layout.setSpacing(true); layout.addComponent(searchBar); layout.addComponent(m_artifactsTable); layout.addComponent(uploadArtifact); layout.addComponent(finalUploadedArtifacts); // The components added to the window are actually added to the window's // layout; you can use either. Alignments are set using the layout layout.addComponent(m_addButton); layout.setComponentAlignment(m_addButton, Alignment.MIDDLE_RIGHT); searchField.focus(); }
From source file:org.apache.ace.webui.vaadin.VaadinClient.java
License:Apache License
private void initGrid() { User user = (User) getUser();//from w w w . ja v a2s. c o m Authorization auth = m_userAdmin.getAuthorization(user); int count = 0; for (String role : new String[] { "viewArtifact", "viewFeature", "viewDistribution", "viewTarget" }) { if (auth.hasRole(role)) { count++; } } final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) { @Override public void updateProgress(long readBytes, long contentLength) { Float percentage = new Float(readBytes / (float) contentLength); m_progress.setValue(percentage); } @Override protected void artifactsUploaded(List<UploadHandle> uploadedArtifacts) { StringBuilder failedMsg = new StringBuilder(); StringBuilder successMsg = new StringBuilder(); Set<String> selection = new HashSet<>(); for (UploadHandle handle : uploadedArtifacts) { if (!handle.isSuccessful()) { // Upload failed, so let's report this one... appendFailure(failedMsg, handle); m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFile() + " failed.", handle.getFailureReason()); } else { try { // Upload was successful, try to upload it to our OBR... ArtifactObject artifact = uploadToOBR(handle); if (artifact != null) { selection.add(artifact.getDefinition()); appendSuccess(successMsg, handle); } } catch (ArtifactAlreadyExistsException exception) { appendFailureExists(failedMsg, handle); m_log.log(LogService.LOG_WARNING, "Upload of " + handle.getFilename() + " failed, as it already exists!"); } catch (Exception exception) { appendFailure(failedMsg, handle, exception); m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFilename() + " failed.", exception); } } // We're done with this (temporary) file, so we can remove it... handle.cleanup(); } m_artifactsPanel.setValue(selection); // Notify the user what the overall status was... Notification notification = createNotification(failedMsg, successMsg); getMainWindow().showNotification(notification); m_progress.setStyleName("invisible"); m_statusLine.setStatus(notification.getCaption() + "..."); } @Override protected void uploadStarted(UploadHandle upload) { m_progress.setStyleName("visible"); m_progress.setValue(new Float(0.0f)); m_statusLine.setStatus("Upload of '%s' started...", upload.getFilename()); } private void appendFailure(StringBuilder sb, UploadHandle handle) { appendFailure(sb, handle, handle.getFailureReason()); } private void appendFailure(StringBuilder sb, UploadHandle handle, Exception cause) { sb.append("<li>'").append(handle.getFile().getName()).append("': failed"); if (cause != null) { sb.append(", possible reason:<br/>").append(cause.getMessage()); } sb.append("</li>"); } private void appendFailureExists(StringBuilder sb, UploadHandle handle) { sb.append("<li>'").append(handle.getFile().getName()) .append("': already exists in repository</li>"); } private void appendSuccess(StringBuilder sb, UploadHandle handle) { sb.append("<li>'").append(handle.getFile().getName()).append("': added to repository</li>"); } private Notification createNotification(StringBuilder failedMsg, StringBuilder successMsg) { String caption = "Upload completed"; int delay = 500; // msec. StringBuilder notification = new StringBuilder(); if (failedMsg.length() > 0) { caption = "Upload completed with failures"; delay = -1; notification.append("<ul>").append(failedMsg).append("</ul>"); } if (successMsg.length() > 0) { notification.append("<ul>").append(successMsg).append("</ul>"); } if (delay < 0) { notification.append("<p>(click to dismiss this notification).</p>"); } Notification summary = new Notification(caption, notification.toString(), Notification.TYPE_TRAY_NOTIFICATION); summary.setDelayMsec(delay); return summary; } private ArtifactObject uploadToOBR(UploadHandle handle) throws IOException { return UploadHelper.importRemoteBundle(m_artifactRepository, handle.getFile()); } }; m_grid = new GridLayout(count, 4); m_grid.setSpacing(true); m_grid.setSizeFull(); m_mainToolbar = createToolbar(); m_grid.addComponent(m_mainToolbar, 0, 0, count - 1, 0); m_artifactsPanel = createArtifactsPanel(); m_artifactToolbar = createArtifactToolbar(); final DragAndDropWrapper artifactsPanelWrapper = new DragAndDropWrapper(m_artifactsPanel); artifactsPanelWrapper.setDragStartMode(DragStartMode.HTML5); artifactsPanelWrapper.setDropHandler(new ArtifactDropHandler(uploadHandler)); artifactsPanelWrapper.setCaption(m_artifactsPanel.getCaption()); artifactsPanelWrapper.setSizeFull(); count = 0; if (auth.hasRole("viewArtifact")) { m_grid.addComponent(artifactsPanelWrapper, count, 2); m_grid.addComponent(m_artifactToolbar, count, 1); count++; } m_featuresPanel = createFeaturesPanel(); m_featureToolbar = createFeatureToolbar(); if (auth.hasRole("viewFeature")) { m_grid.addComponent(m_featuresPanel, count, 2); m_grid.addComponent(m_featureToolbar, count, 1); count++; } m_distributionsPanel = createDistributionsPanel(); m_distributionToolbar = createDistributionToolbar(); if (auth.hasRole("viewDistribution")) { m_grid.addComponent(m_distributionsPanel, count, 2); m_grid.addComponent(m_distributionToolbar, count, 1); count++; } m_targetsPanel = createTargetsPanel(); m_targetToolbar = createTargetToolbar(); if (auth.hasRole("viewTarget")) { m_grid.addComponent(m_targetsPanel, count, 2); m_grid.addComponent(m_targetToolbar, count, 1); } m_statusLine = new StatusLine(); m_grid.addComponent(m_statusLine, 0, 3, 2, 3); m_progress = new ProgressIndicator(0f); m_progress.setStyleName("invisible"); m_progress.setIndeterminate(false); m_progress.setPollingInterval(1000); m_grid.addComponent(m_progress, 3, 3); m_grid.setRowExpandRatio(2, 1.0f); m_grid.setColumnExpandRatio(0, 0.31f); m_grid.setColumnExpandRatio(1, 0.23f); m_grid.setColumnExpandRatio(2, 0.23f); m_grid.setColumnExpandRatio(3, 0.23f); // Wire up all panels so they have the correct associations... m_artifactsPanel.setAssociatedTables(null, m_featuresPanel); m_featuresPanel.setAssociatedTables(m_artifactsPanel, m_distributionsPanel); m_distributionsPanel.setAssociatedTables(m_featuresPanel, m_targetsPanel); m_targetsPanel.setAssociatedTables(m_distributionsPanel, null); addListener(m_statusLine, StatefulTargetObject.TOPIC_ALL, RepositoryObject.PUBLIC_TOPIC_ROOT.concat(RepositoryObject.TOPIC_ALL_SUFFIX)); addListener(m_mainToolbar, StatefulTargetObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH); addListener(m_artifactsPanel, ArtifactObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH); addListener(m_featuresPanel, FeatureObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH); addListener(m_distributionsPanel, DistributionObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH); addListener(m_targetsPanel, StatefulTargetObject.TOPIC_ALL, TargetObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH); m_mainWindow.addComponent(m_grid); // Ensure the focus is properly defined (for the shortcut keys to work)... m_mainWindow.focus(); }
From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadDropAreaLayout.java
License:Open Source License
private void buildLayout() { dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); dropAreaWrapper.setDropHandler(new DropAreaHandler()); }
From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout.java
License:Open Source License
private void buildLayout() { final Upload upload = new Upload(); final UploadHandler uploadHandler = new UploadHandler(null, 0, this, multipartConfigElement.getMaxFileSize(), upload, null, null, softwareModuleManagement); upload.setButtonCaption(i18n.getMessage("upload.file")); upload.setImmediate(true);/*from w w w.ja v a 2s. co m*/ upload.setReceiver(uploadHandler); upload.addSucceededListener(uploadHandler); upload.addFailedListener(uploadHandler); upload.addFinishedListener(uploadHandler); upload.addProgressListener(uploadHandler); upload.addStartedListener(uploadHandler); upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); upload.addStyleName("no-border"); fileUploadLayout = new HorizontalLayout(); fileUploadLayout.setSpacing(true); fileUploadLayout.addStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT); fileUploadLayout.addComponent(upload); fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); fileUploadLayout.addComponent(processBtn); fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); fileUploadLayout.addComponent(discardBtn); fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); fileUploadLayout.addComponent(uploadStatusButton); fileUploadLayout.setComponentAlignment(uploadStatusButton, Alignment.MIDDLE_RIGHT); setMargin(false); /* create drag-drop wrapper for drop area */ dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); dropAreaWrapper.setDropHandler(new DropAreahandler()); setSizeFull(); setSpacing(true); }
From source file:org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons.java
License:Open Source License
private DragAndDropWrapper createDragAndDropWrapper(final Button tagButton, final String name, final Long id) { final DragAndDropWrapper bsmBtnWrapper = new DragAndDropWrapper(tagButton); bsmBtnWrapper.addStyleName(ValoTheme.DRAG_AND_DROP_WRAPPER_NO_VERTICAL_DRAG_HINTS); bsmBtnWrapper.addStyleName(ValoTheme.DRAG_AND_DROP_WRAPPER_NO_HORIZONTAL_DRAG_HINTS); bsmBtnWrapper.addStyleName(SPUIStyleDefinitions.FILTER_BUTTON_WRAPPER); if (getButtonWrapperData() != null) { if (id == null) { bsmBtnWrapper.setData(getButtonWrapperData()); } else {/*from w ww .j a va2 s . c o m*/ bsmBtnWrapper.setData(getButtonWrapperData().concat("" + id)); } } bsmBtnWrapper.setId(getButttonWrapperIdPrefix().concat(name)); bsmBtnWrapper.setDragStartMode(DragStartMode.WRAPPER); bsmBtnWrapper.setDropHandler(getFilterButtonDropHandler()); return bsmBtnWrapper; }
From source file:org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout.java
License:Open Source License
private DragAndDropWrapper createDeleteWrapperLayout() { final Button dropToDelete = new Button(i18n.getMessage("label.components.drop.area")); dropToDelete.setCaptionAsHtml(true); dropToDelete.setIcon(FontAwesome.TRASH_O); dropToDelete.addStyleName(ValoTheme.BUTTON_BORDERLESS); dropToDelete.addStyleName("drop-to-delete-button"); dropToDelete.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); dropToDelete.addStyleName(SPUIStyleDefinitions.DEL_ACTION_BUTTON); dropToDelete.addStyleName("delete-icon"); final DragAndDropWrapper wrapper = new DragAndDropWrapper(dropToDelete); wrapper.setStyleName(ValoTheme.BUTTON_PRIMARY); wrapper.setId(getDeleteAreaId());/*from www . ja v a2 s. c o m*/ wrapper.setDropHandler(this); wrapper.addStyleName("delete-button-border"); return wrapper; }
From source file:org.eclipse.hawkbit.ui.common.table.AbstractTableHeader.java
License:Open Source License
private void buildLayout() { final HorizontalLayout titleFilterIconsLayout = createHeaderFilterIconLayout(); titleFilterIconsLayout.addComponents(headerCaption, searchField, searchResetIcon, showFilterButtonLayout); titleFilterIconsLayout.setComponentAlignment(headerCaption, Alignment.TOP_LEFT); titleFilterIconsLayout.setComponentAlignment(searchField, Alignment.TOP_RIGHT); titleFilterIconsLayout.setComponentAlignment(searchResetIcon, Alignment.TOP_RIGHT); titleFilterIconsLayout.setComponentAlignment(showFilterButtonLayout, Alignment.TOP_RIGHT); if (hasCreatePermission() && isAddNewItemAllowed()) { titleFilterIconsLayout.addComponent(addIcon); titleFilterIconsLayout.setComponentAlignment(addIcon, Alignment.TOP_RIGHT); }/* www . j av a2 s . c o m*/ if (hasCreatePermission() && isBulkUploadAllowed()) { titleFilterIconsLayout.addComponent(bulkUploadIcon); titleFilterIconsLayout.setComponentAlignment(bulkUploadIcon, Alignment.TOP_RIGHT); } titleFilterIconsLayout.addComponent(maxMinIcon); titleFilterIconsLayout.setComponentAlignment(maxMinIcon, Alignment.TOP_RIGHT); titleFilterIconsLayout.setExpandRatio(headerCaption, 0.4F); titleFilterIconsLayout.setExpandRatio(searchField, 0.6F); addComponent(titleFilterIconsLayout); final HorizontalLayout dropHintDropFilterLayout = new HorizontalLayout(); dropHintDropFilterLayout.addStyleName("filter-drop-hint-layout"); dropHintDropFilterLayout.setWidth(100, Unit.PERCENTAGE); if (isDropFilterRequired()) { filterDroppedInfo = new HorizontalLayout(); filterDroppedInfo.setImmediate(true); filterDroppedInfo.setStyleName("target-dist-filter-info"); filterDroppedInfo.setHeightUndefined(); filterDroppedInfo.setSizeUndefined(); displayFilterDropedInfoOnLoad(); final DragAndDropWrapper dropFilterLayout = new DragAndDropWrapper(filterDroppedInfo); dropFilterLayout.setId(getDropFilterId()); dropFilterLayout.setDropHandler(getDropFilterHandler()); dropHintDropFilterLayout.addComponent(dropFilterLayout); dropHintDropFilterLayout.setComponentAlignment(dropFilterLayout, Alignment.TOP_CENTER); dropHintDropFilterLayout.setExpandRatio(dropFilterLayout, 1.0F); } addComponent(dropHintDropFilterLayout); setComponentAlignment(dropHintDropFilterLayout, Alignment.TOP_CENTER); addStyleName("bordered-layout"); addStyleName("no-border-bottom"); }
From source file:org.hip.vif.web.util.UploadComponent.java
License:Open Source License
private Component createDropBox(final IBibliographyTask inTask) { final CssLayout lDropPane = new CssLayout(); lDropPane.setWidth("200px"); //$NON-NLS-1$ lDropPane.setHeight("40px"); //$NON-NLS-1$ lDropPane.addStyleName("v-textfield"); //$NON-NLS-1$ final Label lHint = new Label(Activator.getMessages().getMessage("ui.upload.drop.box")); //$NON-NLS-1$ lHint.setStyleName("vif-drop-hint"); //$NON-NLS-1$ lDropPane.addComponent(lHint);//from w w w.j a v a 2s .co m final DragAndDropWrapper outDrop = new DragAndDropWrapper(lDropPane); outDrop.setDropHandler(new DropHandler() { @Override public AcceptCriterion getAcceptCriterion() { // NOPMD return AcceptAll.get(); } @Override public void drop(final DragAndDropEvent inEvent) { // NOPMD final Transferable lTransferable = inEvent.getTransferable(); if (lTransferable instanceof WrapperTransferable) { final Html5File[] lFiles = ((WrapperTransferable) lTransferable).getFiles(); for (final Html5File lFile : lFiles) { lFile.setStreamVariable(createStreamVariable(lFile.getFileName(), inTask)); } } } }); outDrop.setSizeUndefined(); outDrop.setImmediate(true); return outDrop; }
From source file:org.ikasan.dashboard.ui.administration.panel.PolicyManagementPanel.java
License:BSD License
/** * Helper method to initialise behaviour of the policy name field. * //from w w w .j a v a 2 s.c o m * @return */ protected DragAndDropWrapper initPolicyNameField() { // The policy field name is an autocomplete field. this.policyNameField = new AutocompleteField<Policy>(); this.policyNameField.setWidth("70%"); // We also want it to be drag and drop friendly. final DragAndDropWrapper policyNameFieldWrap = new DragAndDropWrapper(policyNameField); policyNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); // In order to have the auto complete work we must add a query listener. // The query listener gets activated when a user begins to type into // the field and hits the database looking for suggestions. policyNameField.setQueryListener(new AutocompleteQueryListener<Policy>() { @Override public void handleUserQuery(AutocompleteField<Policy> field, String query) { // Iterate over the returned results and add them as suggestions for (Policy policy : securityService.getPolicyByNameLike(query)) { field.addSuggestion(policy, policy.getName()); } } }); // Once a suggestion is selected the listener below gets fired and we populate // associated fields as required. policyNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<Policy>() { @Override public void onSuggestionPicked(final Policy pickedPolicy) { PolicyManagementPanel.this.policy = pickedPolicy; // Populate all the policy related fields. PolicyManagementPanel.this.policyItem = new BeanItem<Policy>(PolicyManagementPanel.this.policy); PolicyManagementPanel.this.policyNameField .setPropertyDataSource(policyItem.getItemProperty("name")); PolicyManagementPanel.this.descriptionField .setPropertyDataSource(policyItem.getItemProperty("description")); if (PolicyManagementPanel.this.policy.getPolicyLink() != null) { PolicyManagementPanel.this.linkedEntity.setVisible(true); PolicyManagementPanel.this.linkType.setVisible(true); PolicyManagementPanel.this.linkTypeLabel.setVisible(true); PolicyManagementPanel.this.linkedEntityLabel.setVisible(true); PolicyManagementPanel.this.linkType.setValue( PolicyManagementPanel.this.policy.getPolicyLink().getPolicyLinkType().getName()); PolicyManagementPanel.this.linkedEntity .setValue(PolicyManagementPanel.this.policy.getPolicyLink().getName()); } else { PolicyManagementPanel.this.linkType.setValue(null); PolicyManagementPanel.this.linkedEntity.setValue(new String()); PolicyManagementPanel.this.linkedEntity.setVisible(false); PolicyManagementPanel.this.linkedEntityLabel.setVisible(false); PolicyManagementPanel.this.linkType.setVisible(false); PolicyManagementPanel.this.linkTypeLabel.setVisible(false); } roleTable.removeAllItems(); // Add all the associated roles to the role table. for (final Role role : policy.getRoles()) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.setDescription("Remove Policy from this Role"); // Add the delete functionality to each role that is added deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { // Update the roles associated with policy // and update in the DB. policy.getRoles().remove(role); PolicyManagementPanel.this.savePolicy(policy); // Once we are happy that the DB call was fine // update the UI components to reflect the change. roleTable.removeItem(role); policyDropTable.removeItem(policy.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } PolicyManagementPanel.this.cancelButton.setVisible(false); PolicyManagementPanel.this.newButton.setVisible(true); PolicyManagementPanel.this.deleteButton.setVisible(true); } }); return policyNameFieldWrap; }
From source file:org.ikasan.dashboard.ui.administration.panel.PrincipalManagementPanel.java
License:BSD License
@SuppressWarnings("deprecation") protected void init() { this.setWidth("100%"); this.setHeight("100%"); VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);//ww w . j a v a 2 s . c o m layout.setSizeFull(); Panel securityAdministrationPanel = new Panel(); securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); securityAdministrationPanel.setHeight("100%"); securityAdministrationPanel.setWidth("100%"); GridLayout gridLayout = new GridLayout(2, 5); gridLayout.setWidth("100%"); gridLayout.setHeight("100%"); gridLayout.setMargin(true); gridLayout.setSizeFull(); Label groupManagementLabel = new Label("Group Management"); groupManagementLabel.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(groupManagementLabel, 0, 0, 1, 0); Label groupSearchHintLabel = new Label(); groupSearchHintLabel.setCaptionAsHtml(true); groupSearchHintLabel.setCaption( VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Group Name field to find a group."); groupSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY); groupSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(groupSearchHintLabel, 0, 1, 1, 1); Label principalNameLabel = new Label("Group Name:"); principalNameLabel.setSizeUndefined(); principalNameField = new AutocompleteField<IkasanPrincipal>(); principalNameField.setWidth("70%"); final DragAndDropWrapper principalNameFieldWrap = new DragAndDropWrapper(principalNameField); principalNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); principalTypeField.setWidth("70%"); descriptionField.setWidth("70%"); descriptionField.setHeight("60px"); roleTable.addContainerProperty("Role", String.class, null); roleTable.addContainerProperty("", Button.class, null); roleTable.setHeight("610px"); roleTable.setWidth("300px"); userTable.addContainerProperty("Associated Users", String.class, null); userTable.setHeight("610px"); userTable.setWidth("300px"); principalDropTable.addContainerProperty("Members", String.class, null); principalDropTable.addContainerProperty("", Button.class, null); principalDropTable.setHeight("700px"); principalDropTable.setWidth("300px"); principalNameField.setQueryListener(new AutocompleteQueryListener<IkasanPrincipal>() { @Override public void handleUserQuery(AutocompleteField<IkasanPrincipal> field, String query) { for (IkasanPrincipal principal : securityService.getPrincipalByNameLike(query)) { field.addSuggestion(principal, principal.getName()); } } }); principalNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<IkasanPrincipal>() { @Override public void onSuggestionPicked(final IkasanPrincipal principal) { PrincipalManagementPanel.this.principal = principal; PrincipalManagementPanel.this.setValues(); } }); GridLayout formLayout = new GridLayout(2, 3); formLayout.setWidth("100%"); formLayout.setHeight("135px"); formLayout.setSpacing(true); formLayout.setColumnExpandRatio(0, .1f); formLayout.setColumnExpandRatio(1, .8f); formLayout.addComponent(principalNameLabel, 0, 0); formLayout.setComponentAlignment(principalNameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(principalNameFieldWrap, 1, 0); Label principalTypeLabel = new Label("Group Type:"); principalTypeLabel.setSizeUndefined(); formLayout.addComponent(principalTypeLabel, 0, 1); formLayout.setComponentAlignment(principalTypeLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(principalTypeField, 1, 1); Label descriptionLabel = new Label("Description:"); descriptionLabel.setSizeUndefined(); formLayout.addComponent(descriptionLabel, 0, 2); formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT); formLayout.addComponent(descriptionField, 1, 2); gridLayout.addComponent(formLayout, 0, 2, 1, 2); principalDropTable.setDragMode(TableDragMode.ROW); principalDropTable.setDropHandler(new DropHandler() { @Override public void drop(final DragAndDropEvent dropEvent) { // criteria verify that this is safe logger.info("Trying to drop: " + dropEvent); if (rolesCombo.getValue() == null) { // Do nothing if there is no role selected logger.info("Ignoring drop: " + dropEvent); return; } final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable(); final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent(); logger.info("sourceContainer.getText(): " + sourceContainer.getText()); Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); final IkasanPrincipal principal = securityService.findPrincipalByName(sourceContainer.getText()); final Role roleToRemove = (Role) rolesCombo.getValue(); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { principalDropTable.removeItem(principal.getName()); principal.getRoles().remove(roleToRemove); securityService.savePrincipal(principal); if (principalNameField.getText().equals(principal.getName())) { roleTable.removeItem(roleToRemove); } } }); principalDropTable.addItem(new Object[] { sourceContainer.getText(), deleteButton }, sourceContainer.getText()); principal.getRoles().add((Role) rolesCombo.getValue()); securityService.savePrincipal(principal); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { Button roleDeleteButton = new Button(); roleDeleteButton.setIcon(VaadinIcons.TRASH); roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); roleDeleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); roleDeleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); principalDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role); } } @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); Label roleTableHintLabel = new Label(); roleTableHintLabel.setCaptionAsHtml(true); roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Roles table below displays the roles that are assigned to the group. Roles can be deleted from this table."); roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY); roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(roleTableHintLabel, 0, 3, 1, 3); gridLayout.addComponent(roleTable, 0, 4); gridLayout.addComponent(userTable, 1, 4); this.rolesCombo = new ComboBox("Roles"); this.rolesCombo.setWidth("90%"); this.rolesCombo.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { final Role role = (Role) event.getProperty().getValue(); if (role != null) { logger.info("Value changed got Role: " + role); List<IkasanPrincipal> principals = securityService.getAllPrincipalsWithRole(role.getName()); principalDropTable.removeAllItems(); for (final IkasanPrincipal principal : principals) { Button deleteButton = new Button(); deleteButton.setIcon(VaadinIcons.TRASH); deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); deleteButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { principalDropTable.removeItem(principal.getName()); principal.getRoles().remove(role); securityService.savePrincipal(principal); if (principalNameField.getText().equals(principal.getName())) { roleTable.removeItem(role); } } }); principalDropTable.addItem(new Object[] { principal.getName(), deleteButton }, principal.getName()); } } } }); Panel roleMemberPanel = new Panel(); roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); roleMemberPanel.setHeight("100%"); roleMemberPanel.setWidth("100%"); GridLayout roleMemberLayout = new GridLayout(); roleMemberLayout.setSpacing(true); roleMemberLayout.setWidth("100%"); roleMemberLayout.setHeight("100%"); Label roleGroupLabels = new Label("Role/Group Associations"); roleGroupLabels.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(roleGroupLabels); Label groupDragHintLabel = new Label(); groupDragHintLabel.setCaptionAsHtml(true); groupDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Drop groups into the table below to assign them the role."); roleMemberLayout.addComponent(roleGroupLabels); roleMemberLayout.addComponent(groupDragHintLabel); roleMemberLayout.addComponent(this.rolesCombo); roleMemberLayout.addComponent(this.principalDropTable); roleMemberPanel.setContent(roleMemberLayout); securityAdministrationPanel.setContent(gridLayout); layout.addComponent(securityAdministrationPanel); VerticalLayout roleMemberPanelLayout = new VerticalLayout(); roleMemberPanelLayout.setWidth("100%"); roleMemberPanelLayout.setHeight("100%"); roleMemberPanelLayout.setMargin(true); roleMemberPanelLayout.addComponent(roleMemberPanel); roleMemberPanelLayout.setSizeFull(); HorizontalSplitPanel hsplit = new HorizontalSplitPanel(); hsplit.setFirstComponent(layout); hsplit.setSecondComponent(roleMemberPanelLayout); // Set the position of the splitter as percentage hsplit.setSplitPosition(65, Unit.PERCENTAGE); hsplit.setLocked(true); this.setContent(hsplit); }