Java Code Examples for com.google.gwt.event.logical.shared.SelectionEvent

The following examples show how to use com.google.gwt.event.logical.shared.SelectionEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: EasyML   Source File: BaseTree.java    License: Apache License 2.0 6 votes vote down vote up
public BaseTree() {
	super(new TreeImageResources(), true);

	this.addStyleName("bda-treedir");

	this.addSelectionHandler(new SelectionHandler<TreeItem>() {
		@Override
		public void onSelection(SelectionEvent<TreeItem> event) {
			TreeItem item = event.getSelectedItem();
			Boolean state = item.getState();
			// [GWT Issue 3660] to avoid pass invoke onSection two times
			TreeItem parent = item.getParentItem();
			item.getTree().setSelectedItem(parent, false);
			if (parent != null)
				parent.setSelected(false);
			item.setState(!state);
		}
	});
}
 
Example 2
Source Project: gwt-material   Source File: MaterialCollection.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onLoad() {
    super.onLoad();

    if (selectable) {
        selectHandler = registerHandler(addSelectionHandler(selectionEvent -> {
            clearActive();
            selectionEvent.getSelectedItem().setActive(true);
        }));

        for (Widget child : getChildren()) {
            if (child instanceof MaterialCollectionItem) {
                child.getElement().getStyle().setCursor(Style.Cursor.POINTER);
                ((MaterialCollectionItem) child).addClickHandler(clickEvent -> SelectionEvent.fire(MaterialCollection.this, (MaterialCollectionItem) child));
            }
        }
    } else {
        removeHandler(selectHandler);
    }
}
 
Example 3
Source Project: gwt-material   Source File: MaterialNavSectionTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testSelectionEvent() {
    MaterialNavSection widget = new MaterialNavSection();

    final boolean[] isSelectionEventFired = {false};
    widget.addSelectionHandler(selectionEvent -> isSelectionEventFired[0] = true);
    widget.fireEvent(new GwtEvent<SelectionHandler<?>>() {
        @Override
        public Type<SelectionHandler<?>> getAssociatedType() {
            return SelectionEvent.getType();
        }

        @Override
        protected void dispatch(SelectionHandler eventHandler) {
            eventHandler.onSelection(null);
        }
    });

    assertTrue(isSelectionEventFired[0]);
}
 
Example 4
Source Project: geowe-core   Source File: CopyElementDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
private ComboBox<VectorLayerInfo> initLayerCombo1() {
					
	VectorLayerProperties properties = GWT
			.create(VectorLayerProperties.class);

	layerStore1 = new ListStore<VectorLayerInfo>(properties.key());

	layerCombo1 = new ComboBox<VectorLayerInfo>(layerStore1,
			properties.name());
	layerCombo1.setEmptyText((UIMessages.INSTANCE.sbLayerComboEmptyText()));
	layerCombo1.setTypeAhead(true);
	layerCombo1.setTriggerAction(TriggerAction.ALL);
	layerCombo1.setForceSelection(true);
	layerCombo1.setEditable(false);
	layerCombo1.enableEvents();
	layerCombo1.setWidth(width);

	layerCombo1.addSelectionHandler(new SelectionHandler<VectorLayerInfo>() {
		@Override
		public void onSelection(SelectionEvent<VectorLayerInfo> event) {
			layerCombo1.setValue(event.getSelectedItem(), true);
		}
	});

	return layerCombo1;
}
 
Example 5
private SelectionHandler<Widget> getTabPanelSelectionHandler() {
	return new SelectionHandler<Widget>() {

		@Override
		public void onSelection(SelectionEvent<Widget> event) {
			if (UIMessages.INSTANCE.empty().equals(getActiveTab())) {
				dataFormatField.setVisible(false);
			} else {
				dataFormatField.setVisible(true);
			}
			if (UIMessages.INSTANCE.wfs().equals(getActiveTab())) {
				vectorFormatCombo.setValue(VectorFormat.GML_FORMAT);
			} else {
				vectorFormatCombo.setValue(null);
			}
			
			if (UIMessages.INSTANCE.gitHubResponseTitle().equals(getActiveTab())) {					
				layerName.setEnabled(false);
			} else {
				layerName.setEnabled(true);
			}
		}
	};
}
 
Example 6
Source Project: gwt-material-addins   Source File: MaterialTreeItem.java    License: Apache License 2.0 6 votes vote down vote up
public void select() {
    // Fire selection event
    SelectionEvent.fire(getTree(), this);

    List<MaterialTreeItem> treeItems = getTreeItems();
    if (!treeItems.isEmpty()) {
        for (MaterialTreeItem treeItem : treeItems) {
            if (hide) {
                treeItem.setVisible(false);
            } else {
                treeItem.setVisible(true);
            }
        }
        // Firing of events based on the status of the tree item
        if (hide) {
            CloseEvent.fire(getTree(), this);
            hide = false;
        } else {
            OpenEvent.fire(getTree(), this);
            hide = true;
        }
    }
}
 
Example 7
Source Project: gwt-material-addins   Source File: MaterialPopupMenuTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void checkSelectionHandler(MaterialPopupMenu popupMenu) {
    final boolean[] isSelectionFired = {false};
    popupMenu.setEnabled(true);
    popupMenu.addSelectionHandler(selectionEvent -> isSelectionFired[0] = true);
    popupMenu.fireEvent(new GwtEvent<SelectionHandler<?>>() {
        @Override
        public Type<SelectionHandler<?>> getAssociatedType() {
            return SelectionEvent.getType();
        }

        @Override
        protected void dispatch(SelectionHandler<?> eventHandler) {
            eventHandler.onSelection(null);
        }
    });
    assertTrue(isSelectionFired[0]);
}
 
Example 8
Source Project: swellrt   Source File: EditorHarness.java    License: Apache License 2.0 6 votes vote down vote up
void initContentOracle() {
  contentOracle = new MultiWordSuggestOracle();

  contentSuggestBox = new SuggestBox(contentOracle);
  contentSuggestBox.getElement().setId("content-box");

  // Some initial content xml strings
  contentOracle.add("");
  contentOracle.add("abcd");

  contentSuggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
    @Override public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
      setFromContentBox();
    }
  });

  String[] extra = extendSampleContent();
  if (extra != null) {
    for (String content : extra) {
      contentOracle.add(content);
    }
  }
}
 
Example 9
Source Project: incubator-retired-wave   Source File: EditorHarness.java    License: Apache License 2.0 6 votes vote down vote up
void initContentOracle() {
  contentOracle = new MultiWordSuggestOracle();

  contentSuggestBox = new SuggestBox(contentOracle);
  contentSuggestBox.getElement().setId("content-box");

  // Some initial content xml strings
  contentOracle.add("");
  contentOracle.add("abcd");

  contentSuggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
    @Override public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
      setFromContentBox();
    }
  });

  String[] extra = extendSampleContent();
  if (extra != null) {
    for (String content : extra) {
      contentOracle.add(content);
    }
  }
}
 
Example 10
@Override
public void selectTab(final int index) {
    if (index < PAGE_LIMIT) {
        // visible pages
        flagSelected(prevSelectedIndex, false);
        super.selectTab(index);
        flagSelected(index, true);
        prevSelectedIndex = index;

        if (index == PAGE_LIMIT - 1 && offPageContainer.getSelectedDeck() == -1) {
            offPageContainer.selectDeck(0);
        }

    } else {
        // off page
        offPageContainer.selectDeck(offPageIndex(index));
        if (getSelectedIndex() == PAGE_LIMIT - 1) {
            SelectionEvent.fire(this, PAGE_LIMIT - 1);
        }
        tabs.lastTab().setText(offPageContainer.getTexts().get(offPageIndex(index)).getText());
        selectTab(PAGE_LIMIT - 1);
    }
}
 
Example 11
/**
 * Folder Tree
 */
public FolderSelectTree() {
	tree = new Tree();
	rootItem.setHTML(Util.imageItemHTML("img/menuitem_childs.gif", "root_schema", "top"));
	rootItem.setStyleName("okm-TreeItem");
	rootItem.setUserObject(new GWTFolder());
	rootItem.setSelected(true);
	rootItem.setState(true);
	tree.setStyleName("okm-Tree");
	tree.addItem(rootItem);
	tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
		@Override
		public void onSelection(SelectionEvent<TreeItem> event) {
			boolean refresh = true;
			TreeItem item = event.getSelectedItem();

			// Case that not refreshing tree and file browser ( right click )
			if (actualItem.equals(item)) {
				refresh = false;
			} else {
				// Disables actual item because on changing active node by
				// application this it's not changed automatically
				if (!actualItem.equals(item)) {
					actualItem.setSelected(false);
					actualItem = item;
				} else {
					refresh = false;
				}
			}

			if (refresh) {
				refresh(true);
			}
		}
	});
	actualItem = tree.getItem(0);
	initWidget(tree);
}
 
Example 12
/**
 * Folder Tree
 */
public FolderSelectTree() {
	tree = new Tree();
	rootItem.setHTML(Util.imageItemHTML("img/menuitem_childs.gif", "root_schema", "top"));
	rootItem.setStyleName("okm-TreeItem");
	rootItem.setUserObject(new GWTFolder());
	rootItem.setSelected(true);
	rootItem.setState(true);
	tree.setStyleName("okm-Tree");
	tree.addItem(rootItem);
	tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
		@Override
		public void onSelection(SelectionEvent<TreeItem> event) {
			boolean refresh = true;
			TreeItem item = event.getSelectedItem();

			// Case that not refreshing tree and file browser ( right click )
			if (actualItem.equals(item)) {
				refresh = false;
			} else {
				// Disables actual item because on changing active node by
				// application this it's not changed automatically
				if (!actualItem.equals(item)) {
					actualItem.setSelected(false);
					actualItem = item;
				} else {
					refresh = false;
				}
			}

			if (refresh) {
				refresh(true);
			}
		}
	});
	actualItem = tree.getItem(0);
	initWidget(tree);
}
 
Example 13
Source Project: gwt-material   Source File: MaterialTab.java    License: Apache License 2.0 5 votes vote down vote up
protected void registerChildHandler(Widget child) {
    if (child instanceof MaterialTabItem) {
        MaterialTabItem item = (MaterialTabItem) child;
        item.getHandlerRegistry().clearHandlers();
        item.registerHandler(item.addMouseDownHandler(e -> SelectionEvent.fire(MaterialTab.this, getChildren().indexOf(child))));
    }
}
 
Example 14
Source Project: sc2gears   Source File: Menu.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Menu.
 */
public Menu( final MenuItem[] menuItems, final Panel pageContainer ) {
	this.menuItems     = menuItems;
	this.pageContainer = pageContainer;
	
	for ( final MenuItem mi : menuItems )
		addTab( mi.getLabel() );
	
	addSelectionHandler( new SelectionHandler< Integer >() {
		@Override
		public void onSelection( final SelectionEvent< Integer > event ) {
			menuItems[ event.getSelectedItem() ].onActivate( Menu.this );
		}
	} );
}
 
Example 15
Source Project: geowe-core   Source File: GeoprocessDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void createComboLayer(final ComboBox<VectorLayerInfo> combo,
		final String numCombo, final TextButton validateButton) {
	clearLayerComboBox(combo);
	combo.setTypeAhead(true);
	combo.setTriggerAction(TriggerAction.ALL);
	combo.setForceSelection(true);
	combo.setEditable(false);
	combo.enableEvents();
	combo.setWidth(WIDTH_COMBO_LAYER);
	combo.setId(numCombo);

	combo.addSelectionHandler(new SelectionHandler<VectorLayerInfo>() {
		@Override
		public void onSelection(SelectionEvent<VectorLayerInfo> event) {
			combo.setValue(event.getSelectedItem(), true);
			List<VectorLayerInfo> updatedLayers = removeLayer(event
					.getSelectedItem());
			if (COMBO1_ID.equals(combo.getId())) {
				updateCombo(LAYER_COMBO_2, LAYER_STORE_2, updatedLayers);
			} else {
				updateCombo(LAYER_COMBO_1, LAYER_STORE_1, updatedLayers);
			}
		}
	});
	
	validateButton.setToolTip(UIMessages.INSTANCE
			.descriptionValidationToolText());

	final HorizontalPanel horizontalGroup = getHorizontalPanel();
	horizontalGroup.add(combo);
	horizontalGroup.add(validateButton);

	panel.add(new Label(UIMessages.INSTANCE.layerLabelText(numCombo)));
	panel.add(horizontalGroup);
}
 
Example 16
Source Project: geowe-core   Source File: GeoprocessDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void createGeoprocessAndDistanceField(final Geoprocesses spatialOperation) {
	spatialOperationComboBox = new GeoprocessComboBox(
			spatialOperation.getAll());
	spatialOperationComboBox.setWidth(WIDTH_SPATIAL_OPERATION_COMBO);
	clearSpatialOperationComboBox();				
	spatialOperationComboBox
			.addSelectionHandler(new SelectionHandler<Geoprocess>() {
				@Override
				public void onSelection(SelectionEvent<Geoprocess> event) {
					spatialOperationComboBox.setValue(
							event.getSelectedItem(), true);

					if (event.getSelectedItem() instanceof BufferGeoprocess) {
						LAYER_COMBO_2.setValue(null);
						LAYER_COMBO_2.setEnabled(false);
						distanceTextField.setText("0");
						distanceTextField.setEnabled(true);
						distanceTextField.setVisible(true);
					} else {							
						LAYER_COMBO_2.setEnabled(true);
						distanceTextField.setText("");
						distanceTextField.setEnabled(false);
						distanceTextField.setVisible(false);
					}
				}
			});

	initDistanceTextField();
	final HorizontalPanel horizontalGroup = getHorizontalPanel();
	horizontalGroup.add(spatialOperationComboBox);
	horizontalGroup.add(distanceTextField);
	panel.add(horizontalGroup);
}
 
Example 17
private void createSelectionHandler() {
	addSelectionHandler(new SelectionHandler<Geoprocess>() {
		@Override
		public void onSelection(SelectionEvent<Geoprocess> event) {
			setValue(event.getSelectedItem(), true);
		}
	});
}
 
Example 18
private void createSelectionHandler() {
	addSelectionHandler(new SelectionHandler<VectorFormat>() {
		@Override
		public void onSelection(SelectionEvent<VectorFormat> event) {
			setValue(event.getSelectedItem(), true);
		}
	});
}
 
Example 19
Source Project: geowe-core   Source File: ExportDataDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private SelectionHandler<VectorFormat> getVectorComboSelectionHandler() {
	return new SelectionHandler<VectorFormat>() {
		@Override
		public void onSelection(SelectionEvent<VectorFormat> event) {
				epsgCombo.enable();
		}
	};
}
 
Example 20
Source Project: gwt-material-demo   Source File: MenuBarView.java    License: Apache License 2.0 5 votes vote down vote up
@UiHandler({"dpFile", "dpNew", "dpView", "dpEdit", "dpFormat"})
void onSelectionFileDropdown(SelectionEvent<Widget> selection) {
    if(selection.getSelectedItem() instanceof MaterialLink){
        MaterialToast.fireToast("Triggered : " + ((MaterialLink)selection.getSelectedItem()).getText());
    }else if(selection.getSelectedItem() instanceof MaterialCheckBox){
        MaterialToast.fireToast("Checked : " + ((MaterialCheckBox)selection.getSelectedItem()).getText());
    }
}
 
Example 21
Source Project: gwt-material-demo   Source File: MenuBarView.java    License: Apache License 2.0 5 votes vote down vote up
@UiHandler("dpMode")
void onSelectionMode(SelectionEvent<Widget> selection) {
    for(Widget w : dpMode.getItems()){
        if(w instanceof MaterialCheckBox){
            ((MaterialCheckBox) w).setValue(false);
        }
    }
    if(selection.getSelectedItem() instanceof MaterialCheckBox){
        ((MaterialCheckBox) selection.getSelectedItem()).setValue(true);
        MaterialToast.fireToast("Checked : " + ((MaterialCheckBox) selection.getSelectedItem()).getText());
    }
}
 
Example 22
Source Project: gwt-material-addins   Source File: JsonTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void load() {
    if (value != null) {
        setId(DOM.createUniqueId());
        options.id = "#" + getId();

        JsTable.jsontotable(value, options);

        $("tr").mousedown((e, handler) -> {
            SelectionEvent.fire(JsonTable.this, $(e.target).parent().asElement());
            return true;
        });
    }
}
 
Example 23
Source Project: gwt-material-addins   Source File: MaterialStepper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Called when a step title is clicked.
 */
@Override
public void onSelection(SelectionEvent<MaterialStep> event) {
    if (stepSkippingAllowed) {
        if (event.getSelectedItem().getState() == State.SUCCESS) {
            goToStep(event.getSelectedItem());
        }
    }
}
 
Example 24
Source Project: gwt-material-addins   Source File: MaterialStep.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onLoad() {
    super.onLoad();

    ClickHandler handler = event -> {
        if (isEnabled() && isVisible()) {
            SelectionEvent.fire(MaterialStep.this, MaterialStep.this);
        }
    };
    registerHandler(header.addClickHandler(handler));
    registerHandler(divTitle.addClickHandler(handler));
    registerHandler(divDescription.addClickHandler(handler));
}
 
Example 25
Source Project: gwt-material-addins   Source File: MaterialStep.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public HandlerRegistration addSelectionHandler(final SelectionHandler<MaterialStep> handler) {
    return this.addHandler(new SelectionHandler<MaterialStep>() {
        @Override
        public void onSelection(SelectionEvent<MaterialStep> event) {
            if (isEnabled()) {
                handler.onSelection(event);
            }
        }
    }, SelectionEvent.getType());
}
 
Example 26
Source Project: gwt-material-addins   Source File: GroupToggleButtonTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testSelectionHandler() {
    Integer SELECTED_ITEM = 1;
    GroupToggleButton<Integer> button = getWidget();

    final boolean[] selectionFired = {false};
    button.addSelectionHandler((SelectionEvent<Integer> selectionEvent) -> {
        assertEquals(SELECTED_ITEM, selectionEvent.getSelectedItem());
        selectionFired[0] = true;
    });

    SelectionEvent.fire(button, SELECTED_ITEM);
    assertTrue(selectionFired[0]);
}
 
Example 27
Source Project: dashbuilder   Source File: GalleryTreeViewImpl.java    License: Apache License 2.0 5 votes vote down vote up
private Tree initNavigationTree() {
    Tree navTree = new Tree();

    List<GalleryTreeNode> mainNodes = galleryTree.getMainNodes();
    populateNavigationTree(mainNodes, navTree);

    navTree.addSelectionHandler(new SelectionHandler<TreeItem>() {
        public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem ti = event.getSelectedItem();
            GalleryTreeNode node = (GalleryTreeNode) ti.getUserObject();
            treeItemClicked(ti, node);
        }
    });
    return navTree;
}
 
Example 28
protected void selectItem(Item item, int idx) {
  if (item != selected) {
    if (selected != null) {
      selected.setSelected(false);
    }
    selected = item;
    if (selected != null) {
      selected.setSelected(true);
    }
    SelectionEvent.fire(this, idx);
  }
}
 
Example 29
/**
 * Selects the tab with the specified text. If there's no tab with the specified text, the selected tab remains
 * unchanged. If there's more than one tab with the specified text, the first one will be selected.
 *
 * @param text
 */
@Override
public void selectTab(final String text) {
    for (int i = 0; i < tabs.size(); i++) {
        if (text.equals(tabs.get(i).getText())) {
            selectTab(i);
            return;
        }
    }

    // not found in visible tabs, should be in off-page
    for (OffPageText opt : offPageContainer.getTexts()) {
        if (text.equals(opt.getText())) {
            if (opt.getIndex() == 0) {
                // the first off-page needs special treatment
                offPageContainer.selectDeck(opt.getIndex());
                if (getSelectedIndex() == PAGE_LIMIT - 1) {
                    SelectionEvent.fire(this, PAGE_LIMIT - 1);
                }
                tabs.lastTab().setText(opt.getText());
                selectTab(PAGE_LIMIT - 1);
            } else {
                selectTab(PAGE_LIMIT - 1 + opt.getIndex());
            }
        }
    }
}
 
Example 30
Source Project: gwt-boot-samples   Source File: HelloWorldView.java    License: Apache License 2.0 4 votes vote down vote up
@UiHandler("foodDropDown")
void handleDropdown(SelectionEvent<Widget> callback) {
	MaterialToast.fireToast(
			"Selected : " + ((MaterialLink) callback.getSelectedItem())
					.getText());
}