List of usage examples for com.vaadin.ui DragAndDropWrapper DragAndDropWrapper
public DragAndDropWrapper(Component root)
From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java
License:BSD License
/** * Helper method to initialise behaviour of the role name field. * //from w w w. j a va 2 s.com * @return */ protected void initPolicyNameField() { // The policy field name is an autocomplete field. this.policyNameField = new AutocompleteField<Policy>(); this.policyNameField.setWidth("80%"); policyNameFieldWrap = new DragAndDropWrapper(this.policyNameField); policyNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); policyNameFieldWrap.setWidth("80%"); // 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) { // Nothing to do } }); }
From source file:org.ikasan.dashboard.ui.administration.panel.UserManagementPanel.java
License:BSD License
@SuppressWarnings("deprecation") protected void init() { this.setWidth("100%"); this.setHeight("100%"); VerticalLayout layout = new VerticalLayout(); layout.setSizeFull();// w ww. j a v a 2s.c om Panel securityAdministrationPanel = new Panel(); securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); securityAdministrationPanel.setHeight("100%"); securityAdministrationPanel.setWidth("100%"); GridLayout gridLayout = new GridLayout(2, 6); gridLayout.setMargin(true); gridLayout.setSpacing(true); gridLayout.setSizeFull(); Label mappingConfigurationLabel = new Label("User Management"); mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE); gridLayout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0); Label userSearchHintLabel = new Label(); userSearchHintLabel.setCaptionAsHtml(true); userSearchHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Username, Firstname or Surname fields to find a user."); userSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY); userSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT); gridLayout.addComponent(userSearchHintLabel, 0, 1, 1, 1); Label usernameLabel = new Label("Username:"); usernameField.setWidth("40%"); final DragAndDropWrapper usernameFieldWrap = new DragAndDropWrapper(usernameField); usernameFieldWrap.setDragStartMode(DragStartMode.COMPONENT); firstName = new AutocompleteField<User>(); firstName.setWidth("40%"); surname = new AutocompleteField<User>(); surname.setWidth("40%"); final TextField department = new TextField(); department.setWidth("40%"); final TextField email = new TextField(); email.setWidth("40%"); final Table roleTable = new Table(); roleTable.addContainerProperty("Role", String.class, null); roleTable.addContainerProperty("", Button.class, null); roleTable.setHeight("520px"); roleTable.setWidth("250px"); usernameField.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserByUsernameLike(query)) { field.addSuggestion(user, user.getUsername()); } } }); usernameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { 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) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } }); firstName.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserByFirstnameLike(query)) { field.addSuggestion(user, user.getFirstName() + " " + user.getSurname()); } } }); firstName.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; usernameField.setText(user.getUsername()); firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { 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) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); } associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } }); surname.setQueryListener(new AutocompleteQueryListener<User>() { @Override public void handleUserQuery(AutocompleteField<User> field, String query) { for (User user : userService.getUserBySurnameLike(query)) { field.addSuggestion(user, user.getFirstName() + " " + user.getSurname()); } } }); surname.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<User>() { @Override public void onSuggestionPicked(User user) { UserManagementPanel.this.user = user; usernameField.setText(user.getUsername()); firstName.setText(user.getFirstName()); surname.setText(user.getSurname()); department.setValue(user.getDepartment()); email.setValue(user.getEmail()); final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername()); roleTable.removeAllItems(); for (final Role role : principal.getRoles()) { 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) { roleTable.removeItem(role); principal.getRoles().remove(role); securityService.savePrincipal(principal); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), deleteButton }, role); associatedPrincipalsTable.removeAllItems(); for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) { if (!ikasanPrincipal.getType().equals("user")) { associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal); } } } } }); GridLayout formLayout = new GridLayout(2, 5); formLayout.setSpacing(true); formLayout.setWidth("100%"); formLayout.setColumnExpandRatio(0, .1f); formLayout.setColumnExpandRatio(1, .8f); usernameLabel.setSizeUndefined(); formLayout.addComponent(usernameLabel, 0, 0); formLayout.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(usernameFieldWrap, 1, 0); Label firstNameLabel = new Label("First name:"); firstNameLabel.setSizeUndefined(); formLayout.addComponent(firstNameLabel, 0, 1); formLayout.setComponentAlignment(firstNameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(firstName, 1, 1); Label surnameLabel = new Label("Surname:"); surnameLabel.setSizeUndefined(); formLayout.addComponent(surnameLabel, 0, 2); formLayout.setComponentAlignment(surnameLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(surname, 1, 2); Label departmentLabel = new Label("Department:"); departmentLabel.setSizeUndefined(); formLayout.addComponent(departmentLabel, 0, 3); formLayout.setComponentAlignment(departmentLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(department, 1, 3); Label emailLabel = new Label("Email address:"); emailLabel.setSizeUndefined(); formLayout.addComponent(emailLabel, 0, 4); formLayout.setComponentAlignment(emailLabel, Alignment.MIDDLE_RIGHT); formLayout.addComponent(email, 1, 4); gridLayout.addComponent(formLayout, 0, 2, 1, 2); Label rolesAndGroupsHintLabel1 = new Label(); rolesAndGroupsHintLabel1.setCaptionAsHtml(true); rolesAndGroupsHintLabel1.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Roles table below displays the roles that the user has. Roles can be deleted from this table."); rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_TINY); rolesAndGroupsHintLabel1.addStyleName(ValoTheme.LABEL_LIGHT); rolesAndGroupsHintLabel1.setWidth(300, Unit.PIXELS); gridLayout.addComponent(rolesAndGroupsHintLabel1, 0, 3, 1, 3); Label rolesAndGroupsHintLabel2 = new Label(); rolesAndGroupsHintLabel2.setCaptionAsHtml(true); rolesAndGroupsHintLabel2.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " The Groups table below displays all the LDAP groups that the user is a member of. You cannot manage these " + "from this application."); rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_TINY); rolesAndGroupsHintLabel2.addStyleName(ValoTheme.LABEL_LIGHT); rolesAndGroupsHintLabel2.setWidth(300, Unit.PIXELS); gridLayout.addComponent(rolesAndGroupsHintLabel2, 0, 4, 1, 4); final ClientSideCriterion acceptCriterion = new SourceIs(usernameField); userDropTable.addContainerProperty("Members", String.class, null); userDropTable.addContainerProperty("", Button.class, null); userDropTable.setHeight("715px"); userDropTable.setWidth("300px"); userDropTable.setDragMode(TableDragMode.ROW); userDropTable.setDropHandler(new DropHandler() { @Override public void drop(final DragAndDropEvent dropEvent) { if (rolesCombo.getValue() == null) { // Do nothing if there is no role selected logger.info("Ignoring drop: " + dropEvent); return; } // criteria verify that this is safe logger.info("Trying to drop: " + dropEvent); 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) { userDropTable.removeItem(principal.getName()); principal.getRoles().remove(roleToRemove); securityService.savePrincipal(principal); if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) { roleTable.removeItem(roleToRemove); } } }); userDropTable.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); userDropTable.removeItem(principal.getName()); } }); roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role); } } @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); gridLayout.addComponent(roleTable, 0, 5); this.associatedPrincipalsTable.addContainerProperty("Groups", String.class, null); this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener); associatedPrincipalsTable.setHeight("520px"); associatedPrincipalsTable.setWidth("400px"); gridLayout.addComponent(this.associatedPrincipalsTable, 1, 5); this.rolesCombo = new ComboBox("Roles"); this.rolesCombo.setWidth("90%"); this.rolesCombo.addValueChangeListener(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()); userDropTable.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) { userDropTable.removeItem(principal.getName()); principal.getRoles().remove(role); securityService.savePrincipal(principal); if (UserManagementPanel.this.usernameField.getText().equals(principal.getName())) { roleTable.removeItem(role); } } }); userDropTable.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%"); Label roleMemberAssociationsLabel = new Label("Role/Member Associations"); roleMemberAssociationsLabel.setStyleName(ValoTheme.LABEL_HUGE); Label userDragHintLabel = new Label(); userDragHintLabel.setCaptionAsHtml(true); userDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Drop users into the table below to assign them the role."); roleMemberLayout.addComponent(roleMemberAssociationsLabel); roleMemberLayout.addComponent(userDragHintLabel); roleMemberLayout.addComponent(this.rolesCombo); roleMemberLayout.addComponent(this.userDropTable); 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); }
From source file:org.jumpmind.metl.ui.views.design.EditFlowPalette.java
License:Open Source License
protected void addItemToFlowPanelSection(String labelName, String componentType, VerticalLayout componentLayout, ClassResource icon, String componentId) { FlowPaletteItem paletteItem = new FlowPaletteItem(labelName); if (componentId != null) { paletteItem.setShared(true);// w ww .j a v a2 s. c om paletteItem.setComponentId(componentId); } else { paletteItem.setComponentType(componentType); paletteItem.setShared(false); } paletteItem.setIcon(icon); paletteItem.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP); paletteItem.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED); paletteItem.addStyleName("leftAligned"); paletteItem.setWidth(100, Unit.PERCENTAGE); DragAndDropWrapper wrapper = new DragAndDropWrapper(paletteItem); wrapper.setSizeUndefined(); wrapper.setDragStartMode(DragStartMode.WRAPPER); componentLayout.addComponent(wrapper); componentLayout.setComponentAlignment(wrapper, Alignment.TOP_CENTER); }
From source file:org.jumpmind.metl.ui.views.design.EditFlowPanel.java
License:Open Source License
public EditFlowPanel(ApplicationContext context, String flowId, DesignNavigator designNavigator, TabbedPanel tabs) {/* w w w . j av a2 s .c om*/ this.configurationService = context.getConfigurationService(); this.flow = configurationService.findFlow(flowId); this.readOnly = context.isReadOnly(configurationService.findProjectVersion(flow.getProjectVersionId()), Privilege.DESIGN); this.context = context; this.tabs = tabs; this.designNavigator = designNavigator; this.propertySheet = new PropertySheet(context, tabs, readOnly); this.propertySheet.setListener((components) -> { List<FlowStep> steps = new ArrayList<FlowStep>(); for (Component c : components) { steps.add(EditFlowPanel.this.flow.findFlowStepWithComponentId(c.getId())); } refreshStepOnDiagram(steps); }); this.propertySheet.setCaption("Property Sheet"); this.componentPalette = new EditFlowPalette(this, context, flow.getProjectVersionId()); addComponent(componentPalette); VerticalLayout rightLayout = new VerticalLayout(); rightLayout.setSizeFull(); rightLayout.addComponent(buildButtonBar()); VerticalSplitPanel splitPanel = new VerticalSplitPanel(); splitPanel.setSizeFull(); splitPanel.setSplitPosition(50, Unit.PERCENTAGE); diagramLayout = new VerticalLayout(); diagramLayout.setWidth(10000, Unit.PIXELS); diagramLayout.setHeight(10000, Unit.PIXELS); DragAndDropWrapper wrapper = new DragAndDropWrapper(diagramLayout); wrapper.setSizeUndefined(); wrapper.setDropHandler(new DropHandler()); flowPanel = new Panel(); flowPanel.setSizeFull(); flowPanel.addStyleName(ValoTheme.PANEL_WELL); flowPanel.setContent(wrapper); splitPanel.addComponent(flowPanel); splitPanel.addComponent(propertySheet); rightLayout.addComponent(splitPanel); rightLayout.setExpandRatio(splitPanel, 1); addComponent(rightLayout); setExpandRatio(rightLayout, 1); if (flow.getFlowSteps().size() > 0) { selected = new ArrayList<AbstractObject>(); selected.add(flow.getFlowSteps().get(0)); propertySheet.setSource(selected); } redrawFlow(); }
From source file:org.lucidj.browser.AbstractCell.java
License:Apache License
public AbstractCell(RendererFactory rendererFactory, Object object) { Component rendered_object;/*from w w w .jav a 2 s .com*/ log.info("Cell: object = {}", object); if (object != null) { // Register and render the source object source_object = object; rendered_object = object_renderer = rendererFactory.newRenderer(source_object); } else { rendered_object = build_insert_here(); } log.info("Cell: rendered_object = {}", rendered_object); // Create and set drag and drop wrapper cell_wrap = new DragAndDropWrapper(rendered_object); cell_wrap.addStyleName("component-cell-wrapper"); if (object == null) // Insert here cell { cell_wrap.addStyleName("no-horizontal-drag-hints"); cell_wrap.addStyleName("no-vertical-drag-hints"); } else // Normal cell { cell_wrap.addStyleName("no-horizontal-drag-hints"); cell_wrap.addStyleName("no-box-drag-hints"); } // Setup DD handlers for component insertion cell_wrap.setData(this); cell_wrap.setDropHandler(this); decorated_cell = new HorizontalLayout(); decorated_cell.setWidth(100, Sizeable.Unit.PERCENTAGE); // Left panel decorated_cell.addComponent(build_left_panel()); // TODO: NOTIFY ObjectRenderer COMPONENT SWAP SO WE CAN UPDATE LISTENERS! decorated_cell.addComponent(cell_wrap); decorated_cell.setExpandRatio(cell_wrap, 1.0f); // Right panel decorated_cell.addComponent(build_right_panel()); // Uses clicks to set where the focus is decorated_cell.addLayoutClickListener(this); }
From source file:org.lucidj.browser.AbstractCell.java
License:Apache License
private Component build_left_panel() { left_panel = new CssLayout(); left_panel.setWidth(32, Sizeable.Unit.PIXELS); left_panel.addStyleName("cell-panel-left"); left_panel.setHeight(100, Sizeable.Unit.PERCENTAGE); String icon_url = "/VAADIN/~/formulas/impossible.png"; String icon_title = "The Unknown"; ComponentInterface component_interface = Aggregate.adapt(ComponentInterface.class, source_object); if (component_interface != null) { // If it is a valid component, displays its icon on the top left corner of the cell ComponentDescriptor descriptor = (ComponentDescriptor) component_interface .getProperty(ComponentDescriptor.DESCRIPTOR); if (descriptor != null) { icon_url = descriptor.getIconUrl(); icon_title = descriptor.getIconTitle(); }//w w w . ja v a2 s . c o m } String component_icon_html = "<img class='component-icon' src='" + icon_url + "' title='" + SafeHtmlUtils.htmlEscape(icon_title) + "'/>"; component_icon = new Label(component_icon_html, ContentMode.HTML); left_panel.addComponent(component_icon); // Put the component in a D&D wrapper and allow dragging it final DragAndDropWrapper panel_dd_wrap = new DragAndDropWrapper(left_panel); panel_dd_wrap.setDragStartMode(DragAndDropWrapper.DragStartMode.COMPONENT_OTHER); panel_dd_wrap.setDragImageComponent(component_icon); panel_dd_wrap.addStyleName("no-horizontal-drag-hints"); panel_dd_wrap.addStyleName("no-box-drag-hints"); // Set the wrapper to wrap tightly around the component panel_dd_wrap.setHeight(100, Sizeable.Unit.PERCENTAGE); panel_dd_wrap.setWidthUndefined(); panel_dd_wrap.setId("test"); // Setup DD handlers for component insertion panel_dd_wrap.setData(this); panel_dd_wrap.setDropHandler(this); // While left_panel is kept in order to be customized, here we return D&D wrapper return (panel_dd_wrap); }
From source file:org.lucidj.browser.ComponentPalette.java
License:Apache License
private boolean add_component_to_palette(ComponentDescriptor component) { String canonical_name = component.getComponentClass(); String icon_title = component.getIconTitle(); log.info("*** => ADDING component {} ({})", canonical_name, component); int base_width = 6; int margin_h_size_px = base_width / 2; int margin_v_size_px = base_width; int icon_size_px = base_width * 6; int font_size_px = 2 * base_width + 2; int icon_box_width_px = base_width * 12; String icon_html = "<div style='text-align: center; height:auto; display:inline-block; " + "margin:" + margin_v_size_px + "px " + margin_h_size_px + "px;" + "width:" + icon_box_width_px + "px; line-height:1.1em;'>" + "<img src='" + component.getIconUrl() + "' " + "width='" + icon_size_px + "px' height='" + icon_size_px + "px' />" + "<div style='white-space:normal; word-wrap:break-word; font-weight: 400;" + "font-size:" + font_size_px + "px;'>" + icon_title + "</div>" + "</div>"; Label icon_label = new Label(icon_html, ContentMode.HTML); icon_label.setWidthUndefined();//from w w w .j a v a2s. c om // Put the component in a D&D wrapper and allow dragging it final DragAndDropWrapper icon_dd_wrap = new DragAndDropWrapper(icon_label); icon_dd_wrap.setDragStartMode(DragAndDropWrapper.DragStartMode.COMPONENT); // Set the wrapper to wrap tightly around the component icon_dd_wrap.setSizeUndefined(); icon_dd_wrap.setData(component); // Set canonical_name for drag-drop AND on the Label for double-click icon_dd_wrap.setId(canonical_name); icon_label.setId(canonical_name); // Remember this association component_to_vaadin.put(component, icon_dd_wrap); // Add the wrapper, not the component, to the layout self.addComponent(icon_dd_wrap); return (true); }
From source file:org.lucidj.iconlist.renderer.IconListRenderer.java
License:Apache License
private AbstractComponent create_icon(Map<String, Object> component) { String icon_title = (String) component.get("iconTitle"); if (icon_title == null) { icon_title = "No title"; }//from w ww . j av a 2s .c om Resource icon_resource = iconHelper.getIcon((String) component.get("iconUrl"), 32); Button button_icon = new Button(icon_title); button_icon.setIcon(icon_resource); button_icon.addStyleName(ValoTheme.BUTTON_BORDERLESS); button_icon.addStyleName(ValoTheme.BUTTON_SMALL); button_icon.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP); button_icon.addStyleName("x-icon-button"); button_icon.addStyleName("icon-size-32"); button_icon.addClickListener(this); button_icon.setWidthUndefined(); button_caption_wrap(button_icon); // Put the component in a D&D wrapper and allow dragging it final DragAndDropWrapper icon_dd_wrap = new DragAndDropWrapper(button_icon); icon_dd_wrap.setDragStartMode(DragAndDropWrapper.DragStartMode.COMPONENT); // Set the wrapper to wrap tightly around the component icon_dd_wrap.setSizeUndefined(); icon_dd_wrap.setData(component); // Set ID for drag-drop AND on the Label for double-click if (component.containsKey("entryId")) { String entryId = (String) component.get("entryId"); icon_dd_wrap.setId(entryId); button_icon.setId(entryId); } // Component data is the map itself button_icon.setData(component); // Remember this association component_to_vaadin.put(component, icon_dd_wrap); return (icon_dd_wrap); }
From source file:org.peergreen.vaadin.diagram.Toolbar.java
License:Open Source License
private Component createDragEntry(final ToolbarItem item) { Entry entry = new Entry(item); DragAndDropWrapper drag = new DragAndDropWrapper(entry) { @Override/* ww w .j a va2s .c o m*/ public Transferable getTransferable(final Map<String, Object> variables) { variables.put("component-type", item.getName()); return super.getTransferable(variables); } }; drag.setSizeUndefined(); drag.setDragStartMode(DragStartMode.COMPONENT); return drag; }
From source file:org.s23m.cell.editor.semanticdomain.ui.components.field.SetField.java
License:Mozilla Public License
private void init() { final VerticalLayout mainLayout = new VerticalLayout(); final Label lbl = new Label(caption); mainLayout.addComponent(lbl);//from w w w.j ava2 s . c om txtField = new TextField(); txtField.setValue(setData.getName()); txtField.setWidth(FIELD_WIDTH); setImmediate(true); setCompositionRoot(mainLayout); txtField.addListener(new Property.ValueChangeListener() { public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) { final String value = (String) txtField.getValue(); setValue(value); } }); // drop handler final DragAndDropWrapper targetWrapper = new DragAndDropWrapper(txtField); targetWrapper.setDropHandler(new DropHandler() { public void drop(final DragAndDropEvent event) { final DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); final TreeNode node = (TreeNode) t.getData("itemId"); setData.setSet(node.getSet()); txtField.setValue(setData.getName()); setValue(node.getSet()); txtField.requestRepaint(); } public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); mainLayout.addComponent(targetWrapper); }