List of usage examples for com.jgoodies.binding.value ValueModel getValue
Object getValue();
From source file:com.salas.bb.views.PagingControl.java
License:Open Source License
/** * Creates a control with the page model. * * @param pageModel the integer model containing the page number. * @param pageCountModel the integer model for the number of pages. *///from www . j a v a2 s. c om public PagingControl(ValueModel pageModel, ValueModel pageCountModel) { super(pageModel); this.pageCountModel = pageCountModel; pageCountModel.addValueChangeListener(new PageCountModelListener()); setPageCount((Integer) pageCountModel.getValue()); pageModel.addValueChangeListener(new PageModelListener()); }
From source file:de.awtools.groovy.swinger.bean.PresentationModelTest.java
License:Open Source License
@Test public void testGroovyPresentationModel_bean_to_model() { final String theOldValue = "the_old_value"; final String theNewValue = "the_new_value"; person.setName("Winkler"); ////from w ww. j av a 2s .c o m // Property change propagation works fine with #setProperty(...) // person.setProperty("name", "My new name"); assertThat(person.getName()).isEqualTo("My new name"); // => ValueModel has changed!!! assertThat(vm.getValue()).isEqualTo("My new name"); assertThat(gpm.getModel("name").getValue()).isEqualTo("My new name"); // // But with #setName(...) the change will be lost! // person.setName("Winkler"); assertThat(person.getName()).isEqualTo("Winkler"); // => ValueModel has not changed!!! assertThat(vm.getValue()).isNotEqualTo("Winkler"); ValueModel newPersonNameValueModel = gpm.getModel("name"); assertEquals(newPersonNameValueModel, vm); assertEquals(newPersonNameValueModel.getValue(), "My new name"); //assertThat(newPersonNameValueModel.getValue()).isNotEqualTo("My new name"); // Direct method call of the property does not work #setName(...) person.setName(theNewValue); assertEquals(theNewValue, person.getName()); // ... but the ValueModel holds the old value! assertEquals("My new name", vm.getValue()); assertEquals("My new name", gpm.getModel("name").getValue()); person.setProperty("name", "Groth"); assertEquals("Groth", vm.getValue()); }
From source file:de.awtools.groovy.swinger.beanbinding.AddressBindingWithJavaTest.java
License:Open Source License
@Test public void testAddressBindingWithJava() { // Groovy class with @Bindable annotation. Address address = new Address(); address.setStreet("Mensingstr"); // Create a presentation model which produces the ValueModels for // every property. GroovyPresentationModel gpm = new GroovyPresentationModel(address); ValueModel model = gpm.getModel("street"); // Check the behavior... assertEquals("Mensingstr", model.getValue()); address.setStreet("Beisenstr"); assertEquals("Beisenstr", model.getValue()); }
From source file:de.dal33t.powerfolder.ui.dialog.directory.DirectoryChooser.java
License:Open Source License
private void newDirectoryAction() { // Select the currently selected directory if (tree.getSelectionPath() == null || !(tree.getSelectionPath().getLastPathComponent() instanceof DirectoryTreeNode)) { return;/*from w w w . j av a 2s.c o m*/ } DirectoryTreeNode dtn = (DirectoryTreeNode) tree.getSelectionPath().getLastPathComponent(); Path selected = dtn.getDir(); String baseFile = selected.toAbsolutePath().toString(); if (baseFile != null) { ValueModel subDirValueModel = new ValueHolder(); NewDirectoryCreator ndc = new NewDirectoryCreator(getController(), true, baseFile, subDirValueModel); ndc.open(); Object o = subDirValueModel.getValue(); if (o != null) { String subDir = ((String) o).trim(); if (subDir.length() > 0) { Path f = Paths.get(baseFile, subDir); if (Files.exists(f)) { DialogFactory.genericDialog(getController(), Translation.getTranslation("dialog.directorychooser.new.description"), Translation.getTranslation("dialog.directorychooser.new.exists", f.toAbsolutePath().toString()), GenericDialogType.WARN); } else { boolean success = false; try { Files.createDirectories(f); success = true; } catch (IOException ioe) { logInfo(ioe.getMessage()); } if (success) { TreePath selectionPath = tree.getSelectionPath(); Object parentComponent = selectionPath.getLastPathComponent(); if (parentComponent instanceof DirectoryTreeNode) { // Expand parent of new folder, so new child // shows. DirectoryTreeNode parentNode = (DirectoryTreeNode) parentComponent; model.insertNodeInto(new DirectoryTreeNode(getController(), null, f, false, true), parentNode, parentNode.getChildCount()); // Find new folder in parent. Enumeration children = parentNode.children(); while (children.hasMoreElements()) { Object node = children.nextElement(); if (node instanceof DirectoryTreeNode) { DirectoryTreeNode childNode = (DirectoryTreeNode) node; if (childNode.getUserObject() instanceof File) { Path childFile = ((File) childNode.getUserObject()).toPath(); if (childFile.equals(f)) { // Expand to child. TreeNode[] childPathNodes = model.getPathToRoot(childNode); TreePath childPath = new TreePath(childPathNodes); tree.setSelectionPath(childPath); tree.scrollPathToVisible(childPath); break; } } else { TreeNode[] pathNode = model.getPathToRoot(childNode); TreePath path = new TreePath(pathNode); tree.setSelectionPath(path); tree.scrollPathToVisible(path); } } } } } else { DialogFactory.genericDialog(getController(), Translation.getTranslation("dialog.directorychooser.new.description"), Translation.getTranslation("dialog.directorychooser.new.problem", f.toAbsolutePath().toString()), GenericDialogType.WARN); } } } } } }
From source file:de.dal33t.powerfolder.ui.util.FileSelectorFactory.java
License:Open Source License
/** * Creates a file selection field. A browse button is attached at the right * side//from w w w .ja va 2 s . com * * @param title the title of the filechoose if pressed the browse button * @param fileSelectionModel the file base value model, will get/write base as String * @param fileSelectionMode the selection mode of the filechooser * @param fileFilter the filefilter used for the filechooser. may be null will * ignore it then * @param open true ? show open dialog : show save dialog * @return */ public static JComponent createFileSelectionField(final String title, final ValueModel fileSelectionModel, final int fileSelectionMode, final FileFilter fileFilter, final boolean open) { if (fileSelectionModel == null) { throw new NullPointerException("Filebase value model is null"); } if (fileSelectionModel.getValue() != null && !(fileSelectionModel.getValue() instanceof String)) { throw new IllegalArgumentException("Value of fileselection is not of type String"); } // text button FormLayout layout = new FormLayout("122dlu, 3dlu, pref", "pref"); PanelBuilder builder = new PanelBuilder(layout); // The textfield final JTextField textField = BasicComponentFactory.createTextField(fileSelectionModel, false); textField.setEditable(false); Dimension p = textField.getPreferredSize(); p.width = Sizes.dialogUnitXAsPixel(30, textField); textField.setPreferredSize(p); // The button final JButton button = new JButtonMini(Icons.getIconById(Icons.DIRECTORY), Translation.getTranslation("folder_create.dialog.select_directory.text")); // Button logic button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File fileSelection = null; if (fileSelectionModel.getValue() != null) { fileSelection = new File((String) fileSelectionModel.getValue()); } JFileChooser fileChooser = DialogFactory.createFileChooser(); fileChooser.setFileSelectionMode(fileSelectionMode); if (fileSelection != null) { fileChooser.setSelectedFile(fileSelection); fileChooser.setCurrentDirectory(fileSelection); } fileChooser.setDialogTitle(title); fileChooser.setFileSelectionMode(fileSelectionMode); if (fileFilter != null) { fileChooser.setFileFilter(fileFilter); } int result; if (open) { result = fileChooser.showOpenDialog(button); } else { result = fileChooser.showSaveDialog(button); } File selectedFile = fileChooser.getSelectedFile(); if (result == JFileChooser.APPROVE_OPTION && selectedFile != null) { fileSelectionModel.setValue(selectedFile.getAbsolutePath()); } } }); CellConstraints cc = new CellConstraints(); builder.add(textField, cc.xy(1, 1)); builder.add(button, cc.xy(3, 1)); JPanel panel = builder.getPanel(); panel.addPropertyChangeListener("enabled", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { boolean enabled = (Boolean) evt.getNewValue(); textField.setEnabled(enabled); button.setEnabled(enabled); } }); return panel; }
From source file:de.dal33t.powerfolder.ui.wizard.MultiOnlineStorageSetupPanel.java
License:Open Source License
/** * PFC-2284: FIXME: Runs in EDT/*ww w . jav a 2 s . c om*/ * * @param folderInfo * @return */ private String getOwnerDisplayname(final FolderInfo folderInfo) { if (!serverClient.isConnected() || !serverClient.isLoggedIn()) { return null; } if (serverClient.getAccount().hasOwnerPermission(folderInfo)) { return null; } final ValueModel ownerDisplaynameModel = new ValueHolder(); final Semaphore sem = new Semaphore(0); Runnable retriever = new Runnable() { @Override public void run() { String ownerDisplayname; try { ownerDisplayname = serverClient.getFolderService().getOwnerDisplayname(folderInfo); } catch (RemoteCallException e) { Logger.getLogger(MultiOnlineStorageSetupPanel.class.getName()) .warning("Unsupported/Old server. Not able to retrieve owner name of " + folderInfo.getName() + ". " + e); ownerDisplayname = ""; } ownerDisplaynameModel.setValue(ownerDisplayname); sem.release(); } }; getController().getIOProvider().startIO(retriever); try { sem.acquire(); } catch (InterruptedException e) { } return (String) ownerDisplaynameModel.getValue(); }
From source file:fi.smaa.jsmaa.gui.presentation.test.PreferencePresentationModelTest.java
License:Open Source License
@Test public void testGetModel() { ValueModel vModel = pmodel.getModel(PreferencePresentationModel.PREFERENCE_TYPE); assertEquals(PreferencePresentationModel.PreferenceType.MISSING, vModel.getValue()); }
From source file:net.sf.housekeeper.swing.util.BoundComponentFactory.java
License:Open Source License
/** * Creates a JSpinner whose value is bound to the given ValueModel. This * means, that the value of the spinner and the value of the ValueModel are * synchronized bidirectionally. Additionally, the spinner uses * the current locale's short format for displaying a date. * /* w w w . j a v a 2s .com*/ * @param valueModel the model that provides the value. Must not be null and * must provide {@link Date}objects. * @return A spinner whose value is bound to <code>valueModel</code>. */ public static JSpinner createDateSpinner(final ValueModel valueModel) { assert valueModel != null : "Parameter valueModel must not be null"; assert valueModel.getValue().getClass() .equals(Date.class) : "valueModel must provide Date objects as values"; final SpinnerDateModel model = new SpinnerDateModelAdapter(valueModel); //Need to truncate the current date for correct spinner operation model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); model.setCalendarField(Calendar.DAY_OF_MONTH); final JSpinner spinner = new JSpinner(model); //Set the spinner's editor to use the current locale's short date // format final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT); final String formatPattern = dateFormat.toPattern(); spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern)); return spinner; }
From source file:net.sf.housekeeper.swing.util.SpinnerDateModelAdapter.java
License:Open Source License
/** * Creates a new adapter which synchronizes with <code>subject</code>. The * initial date is set to the subject's value. All other settings use the * defaults from {@link SpinnerDateModel#SpinnerDateModel()}. * // w w w . j av a 2 s . c o m * @param subject The subject to synchronize the date with. Must not be null * and must provide {@link Date}objects as values. */ public SpinnerDateModelAdapter(final ValueModel subject) { super(); assert subject != null : "Parameter valueModel must not be null"; assert subject.getValue().getClass().equals(Date.class) : "valueModel must provide Date objects as values"; this.subject = subject; setValue(subject.getValue()); subject.addValueChangeListener(this); }
From source file:org.drugis.addis.gui.components.NotEmptyValidator.java
License:Open Source License
private boolean checkFieldsEmpty() { boolean empty = false; for (JComponent f : d_fields) { if (f instanceof JTextComponent) { JTextComponent tf = (JTextComponent) f; if (tf.getText().length() == 0) { empty = true;//w ww . j av a 2 s . c o m break; } } else if (f instanceof JComboBox) { if (((JComboBox) f).getSelectedItem() == null) { empty = true; break; } } else if (f instanceof JDateChooser) { if (((JDateChooser) f).getDate() == null) { empty = true; break; } } else if (f instanceof JList) { JList list = (JList) f; if (list.getModel().getSize() < 2) { empty = true; break; } } } for (ValueModel vm : d_valModels) { if (vm.getValue().equals("")) { empty = true; break; } } return empty; }