Howto veto a selection Change in a JTree...
Hello,
i want to veto a SelectionChange in a javax.swing.JTree, and have found that such a thing is not supported by this Component.
What is the best way to implement a java.beans.VetoableChangeEvent Support on a SelectionChange in a javax.swing.JTree.
Has anybody done this thing, so that i do not have to reinvent the wheel again?
The princips of constrained Properties are clear for me, but
what Methods i have to overwrite in JTree?
Any suggestions are welcome.
with kind regards, carsten
Hi,
my approach is a little diffrent from yours. The left side of my App holds a Tree (single selection). The right side an Editor. If you select a Entry in Tree, the Data is loaded to the editor. If you change the selection to another Tree entry, the data in the Editor is validated, saved, and the Data of the new selected Entry is loaded. Now, if validation fails, the selectionChange should not take place (the Errors are marked by a Forms Framework), so that the user can correct them. I think, this is a requirement that very often occurs.
My approach to handle this requirement:
(I know that this does not work without adjustment. This first approach is only an idea). What do you think about that?
public class VetoableTreeSelectionModel extends DefaultTreeSelectionModel {
private java.beans.VetoableChangeSupport vetoes = new VetoableChangeSupport(this);
public VetoableTreeSelectionModel() { }
public void addSelectionPaths(TreePath[] paths){
if(!getVetoes()){
super.addSelectionPaths(paths);
public void addSelectionPath(TreePath path) {
if(!getVetoes()){
super.addSelectionPath(path);
public void setSelectionPaths(TreePath[] paths){
if(!getVetoes()){
super.setSelectionPaths(paths);
public void setSelectionPath(TreePath path) {
if(!getVetoes()){
super.setSelectionPath(path);
private boolean getVetoes(){
boolean result = false;
try{
vetoes.fireVetoableChange("Path", oldValue , newValue);
System.out.println("### I have received NO vetoes.");
}catch(java.beans.PropertyVetoException ex){
System.out.println("### I have received a veto!");
result=true;
return result;
public void addSeletionChangedVetoListener(VetoableChangeListener listener){
vetoes.addVetoableChangeListener(listener);
public void removeSeletionChangedVetoListener(VetoableChangeListener listener){
vetoes.removeVetoableChangeListener(listener);
}carsten
Similar Messages
-
How to veto a JComboBox selection change in ItemListener
I have a JComboBox whose current value is tied to some data cached in my application. I want to be able to examine the selection in an ItemListener attached to the JComboBox, and if the value is different than what I have cached, I want to ask the user if they really want to change because the change will render some other data as no longer valid. If the user wants to abandon the change, then I want to "abandon" or "veto" the selection change and reset it to the old value.
For instance, if the combo box has values "Foo" and "Bar" in it, and "Foo" is the cached selection, then the user goes and changes the selection to "Bar", I want to prompt them with something like "You have changed the value to Bar. Doing so will render XXX no longer valid. Do you want to continue?" -- if they cancel the change, then leave the selection as "Foo".
What is the best way to do this within ItemListener's itemStateChanged? Are there better ways to do this besides what I've outlined? I didn't see anything in "Core JFC" book or the JDK documentation that discussed this sort of thing.
Thanks in advance,
EricHi,
It is a design problem and not realy a language problem... The way I create vetoing design it that a keep the previous selection of the JComboBox... upon action I look if the application can do the new computation...if not...ask the user... if true| run calculations if not set the JComboBox to the previous selection...
JRG -
How to generate selection change event through code in JTree?
I am developing an application which downloads the file from other system and adds it into the tree. On selecting any file in the tree I m displaying it's contents. But now i am trying to display the contents of downloaded file as soon as it's download completes. Here i am not getting the way to how to generate the event as the download completes, because i tried that setSelectionPath(TreePath path), but it also don't generates the selection change event. Is there any other way to do so?
Put null in place of oldLeadSelectionPath. From the API for TreeSelectionEvent:
protected TreePath oldLeadSelectionPath:
leadSelectionPath before the paths changed, may be null.
I'm at the office and can't try out anything, so please let me know whether that works for you.
db
edit Or it may be easier to put all code from your valueChanged (...) override in a new method and invoke that method both from valueChanged (...) and wherever else you need.
Edited by: Darryl.Burke -
How to 'veto' a jList selection change
Hi All,
I have a JList which I'm using as a record selector - so whenever my user selects an item on the list, the associated record is loaded up into the other controls on this form for editing. If the user edits any of the data items, I want to ask whether to save changes or not if another item is selected from the JList. So, I've added code in my 'selection changed' function to check for changes and show a 'yes/no/cancel' JOptionPane. The code for my 'yes' and 'no' respones work fine - either save the changes or not, then show the next record. My problem is handling if a user clicks cancel...
If the user selects 'Cancel', I dont want any of my "show new record" code to execute (this is easy, I can just 'return' out of the function) but also I don't want the JList selection to change. I've tried calling setSelectedIndex() back to the originally selected item, but this in turn triggers my 'selection changed' function to be called again, which causes the user to be asked twice whether they want to save changes!
So, what I'm after is a kind of beforeSelectionChanged event, which allows the possibility of denying the selection change - but it doesn't look like this exists! I vaguely remember another language (possibly C++/MFC) having this - the user's action could be ignored depending on the return value of the function. Can anyone offer a way of achieving this in Java?
(It's been a while since I last touched Java, and I'm a complete n00b with Swing. Using NetBeans as my IDE.)
Thanks in advance for any suggestions!
AndyThe way I do it, is to implement a VetoableSelectionModel similar to a bean with a vetoable property: on selection change it queries registered VetoableChangeListeners if they don't object and backs out if one of them barks.
HTH
Jeanette -
How to block lead selection change in a tree ?
Hi Guys,
<u>Scenario</u>
I have MasterTree - DetailEditor pair. <i>MasterTree</i> is used to visit some tree-structured data and <i>DetailEditor</i> is used to edit currently selected tree node.
<u>Requirement</u>
If currently selected node data is updated through <i>DetailEditor</i> and needs to be saved, than on a subsequent tree selection change the user should be warned about unsaved data.
<u>Implementation</u>
In <b>onAction</b> event handler of <i>MasterTree</i> I check whether last selected node data is updated and needs to be saved and if this is the case rollback <i>treeSelection</i> to that node. On the time <b>onAction</b> event handler is called the tree selection is changed from the node that needs save to the newly selected node. In order to rollback <i>treeSelection</i> I need to introduce variable referencing last selected tree node.
<u>Question</u>
Is there any other technique to implement above scenario without using additional variable and manually rollback <i>treeSelection</i> ? For example, to plug in WDP framework on validation step just before lead selection is changed.
Thanks in advanceAlex,
Here is a link to the phase model of WD:
http://help.sap.com/saphelp_nw04/helpdata/en/b8/cd96edb9c8794aa362e6e8b4236a1f/frameset.htm
There aren't any hooks provided prior to the event handlers being called. As far as I can tell, the way you are handling it is the only way that will work.
-Cindy -
Discontiguous selection model on a jtree
Hi Frank
I have a jtree bound to and adf model. i have set the branch accessor rule on the binding.
when i set the selection model to discontiguous then it wont allow me to crtl select all the items .
it does however allow me to select some of the items but i cannot do things such as select mutiple parent nodes.
is there any bug that you know about.
please if any one can help
thanks
GeorgeOur tree binding only supports single selection by default since there is only really the notion in a rowset of a single "current" row. Our developers believe that you can implement your own custom selection model to give some application-specific meaning to what the multiple-select would do in your app, but we have not thoroughly tested custom selection models with the JTree.
-
Reacting on selection-changes in a JTable...
Hello,
I created an AbstractTableModel which is the basic for my JTable. Now I want to react on changes of the selection in the table. So I implemented a ListSelectionListener and overwrote the valueChanged()-method. But there is no reaction when the selection changes...is there a special trick with this method, or what else could be the reason for my problem ?
Thanx,
FindusDid you register your listener?
yourTable().getSelectionModel().addListSelectionListener(yourListener); -
Hi All,
I need to observer selection change. How do i go about it. In basicpersistinterface the kBPISelectionObserverImpl is bound with the panel. Similarly I want to call a method on selection change and not update some UI, so where do i need to put my ActiveSelectionObserver.
It can be just displaying an alert of selection change, but how do we trap it.
Please contribute your valuable suggestions.
Thanks in advance.
Jasmine ShaikhYou can aggregate your observer to any easily accessed boss that's permanently around. For example kSessionBoss already has 15 observers, kAppBoss has 7 observers. You would use a private IID, though. Invoke AutoAttach from a StartupShutdown service.
Given that, you're probably wrong architecture-wise by watching the selection without UI involved. There are plenty other notifications, besides there are also different mechanisms to watch the selection from closer on (e.g. SelectionExt). Can you give more details on your intent?
Dirk -
How to change images of selected items in gridview on selection changed event in universal app
Hi,
I am developing Universal App. I have bind the images to the Gridview using ObservableCollection. I have set gridview
SelectionMode as Multiple . I want to change the images of selected items but I don't know how to do in Selection Changed event of Gridview. I got selected items with the help of
Gridview SelectedItems property. How can i change the images of respected selected items?
Please reply me asap.
Thanks in advance.Hi, Sorry for late reply,
Please change the class :
public class ImageCollection : INotifyPropertyChanged
private string source;
public string Source
get { return source; }
set { SetProperty(ref source, value); }
public int MyProperty { get; set; }
protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
if (!object.Equals(storage, value))
storage = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
protected void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
public event PropertyChangedEventHandler PropertyChanged;
XAML
<GridView x:Name="gd"
Tapped="gd_Tapped">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="300" Width="250">
<Image Source="{Binding Source}" Stretch="Fill"/>
<Grid Height="100" Background="#B2000000" VerticalAlignment="Bottom">
<TextBlock Text="{Binding MyProperty}" FontSize="25" />
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
C#
//ObservableCollection of class
ObservableCollection<ImageCollection> img = new ObservableCollection<ImageCollection>();
public MainPage()
this.InitializeComponent();
img.Add(new ImageCollection() { MyProperty = 1, Source = "ms-appx:///Assets/Logo.scale-100.png" });
img.Add(new ImageCollection() { MyProperty = 2, Source = "ms-appx:///Assets/2.jpg" });
img.Add(new ImageCollection() { MyProperty = 3, Source = "ms-appx:///Assets/3.jpg" });
img.Add(new ImageCollection() { MyProperty = 4, Source = "ms-appx:///Assets/4.jpeg" });
gd.ItemsSource = img;
private void gd_Tapped(object sender, TappedRoutedEventArgs e)
GridView gv = (GridView)sender;
ImageCollection ic = gv.SelectedItem as ImageCollection;
ic.Source = "ms-appx:///Assets/4.jpeg";
gv.UpdateLayout();
I have used INotifyPropertyChanged now UI is not fluctuate
and I have not bind again O-Collection.
I hope so You will get right answer.
shah -
Spark Datagrid Selection change Event
starting to work with the spark datagrid.
I want to send off a web service using the values of a row right after they get done editing the row and leave it.
No more change event that I can see like MX and gridItemEditorSessionSaveHandler kicks on every tab between cells
if I use event.currentTarget.selectedItem
Selection Change gives me the new row.
Selection Changing only kicks with mouse row changes not tabs
Suggestions?
I want to register the row with both mouse (on a numeric stepper) and tab(for text fields) events.
Thanks
Dan PrideHi Dan,
Try valueCommit event handler, but I'm not 100% sure that is triggered upon dataProvider data changes.
Another way is to listen for changes in the dataProvider variable. -
Dear all,
I'm newbie of javafx and I'm working on my first application.
I found several issues, for now it doesnt' seems to me a very productive environment, due to lack of components and documentation.
Now I stopped on a very basical question, but I can't go on.
Iìve a combobox and I want to implement selection changed logic, that is basing on selected value some logic must be run.
I didn't find any event like selection changed.
Can you help me with some code or links?
Thanks,
RegardsI guess you actually want to use a ChoiceBox (there is no ComboBox class in JavaFX :p).
The best way I have in mind is binding the ChoiceBox.selectedItem to a variable and set an onreplace trigger on it. Like that:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
var choiceBox: ChoiceBox;
var currentItem = bind choiceBox.selectedItem on replace{
println("{currentItem} selected!");
Stage {
title: "MyApp"
scene: Scene {
width: 200
height: 100
content: [
choiceBox = ChoiceBox {
items: ["Item1","Item2","Item3", "Item4"]
} -
JTabbedPane - Catching tab selection change
I want to catch each tab selection change in my JTabbedPane.
When I used ChangeListener, my program was unable to correctly
indicate selected tab in some cases, i.e.:
JTabbedPane contains two tabs: 0,1.
Tab 0 was selected.
Tab 0 was deleted.
In this case JTabbedPane selects tab 1, but selected index remains
unchanged and stateChanged is not called. How can I catch this?This trick is working, but you see, the problem is more
complicated. The problem is that stateChanged() doesn't work
when index remains unchanged. This is also true for insertTab().
Both insertTab() and removeTabAt() (and maybe smth. else) causes this problem.
Maybe, possible solution will be to override some method of
JTabbedPane, responsible for activating a tab like this...?
tabbedPane = new JTabbedPane {
activateTab(...) {
super.activateTab(...);
firePropertyChange(...);
}But what is the methods prototype and can it be overriden
at all??
In the deep sources of swing :) I've found such tricks:
In JTabbedPane.insertTab():accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
null, component);In JTabbedPane.removeTabAt():accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
component, null);I'm almost convinced that this is the point. But!
I've never worked with Accesibility :(
And I couldn't find out what to do having only swing sources.
Need help. -
How can I set a property when an event happens? (selection changed on datagrid)
I have a datagrid, I would like to change the backgrund of the datagrid when the selection changed event is fired.
I can not use data trigger, because is in the case that I expected a value, but in this case is when change, to any value.
An option is to use an event trigger, but all the examples that I have found is to use with an actions, and I just want to set a property.
How could I do that?
I am using MVVM pattern, so I would like to avoid the use in code-behind.
Thank so much.You could use an event trigger and implement your own TriggerAction<T> that sets the background property. There is an example of how to create a custom TriggerAction available here:
http://stackoverflow.com/questions/942548/setting-a-property-with-an-eventtrigger.
The following example sets the Background property of the DataGrid to a red SolidColorBrush when the SelectionChanged event is fired. It should give you the idea:
<DataGrid x:Name="dgrid"
xmlns:local="clr-namespace:WpfApplication22">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<local:SetPropertyAction PropertyName="Background" TargetObject="{Binding ElementName=dgrid}">
<local:SetPropertyAction.PropertyValue>
<SolidColorBrush>Red</SolidColorBrush>
</local:SetPropertyAction.PropertyValue>
</local:SetPropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
namespace WpfApplication22
public class SetPropertyAction : TriggerAction<FrameworkElement>
public string PropertyName
get { return (string)GetValue(PropertyNameProperty); }
set { SetValue(PropertyNameProperty, value); }
public static readonly DependencyProperty PropertyNameProperty
= DependencyProperty.Register("PropertyName", typeof(string),
typeof(SetPropertyAction));
public object PropertyValue
get { return GetValue(PropertyValueProperty); }
set { SetValue(PropertyValueProperty, value); }
public static readonly DependencyProperty PropertyValueProperty
= DependencyProperty.Register("PropertyValue", typeof(object),
typeof(SetPropertyAction));
public object TargetObject
get { return GetValue(TargetObjectProperty); }
set { SetValue(TargetObjectProperty, value); }
public static readonly DependencyProperty TargetObjectProperty
= DependencyProperty.Register("TargetObject", typeof(object),
typeof(SetPropertyAction));
protected override void Invoke(object parameter)
object target = TargetObject ?? AssociatedObject;
PropertyInfo propertyInfo = target.GetType().GetProperty(
PropertyName,
BindingFlags.Instance|BindingFlags.Public
|BindingFlags.NonPublic|BindingFlags.InvokeMethod);
propertyInfo.SetValue(target, PropertyValue);
For more information about how to hook up event triggers and handle events in MVVM, please refer to my blog post:
http://blog.magnusmontin.net/2013/06/30/handling-events-in-an-mvvm-wpf-application/
Please also remember to mark helpful posts as answer. -
Detail Table Not Changing When Master Table Selection Changes
Using JDev 11.1.1.6.
I am working through some Oracle tutorials (Storefront Demos).
I am accessing the Fusion Order Demo (FOD) schema.
I have created VOs based on BCs for Categories, Subcategories and Products.
I have added all to my data model and tested functionality using the AppModule. This works as expected.
When I drag the Subcategories onto my jsf page as Master-Detail (Table-Table), the initial list is based on the first index of the BrowseCategory data control.
When I click on another row in the master table, the detail table refreshes but the same data appears.
I confirmed that the selection changes on the master table.
I added a button on the page and checked the BrowseCategoryIterator using some backing bean code and the iterator remains on the first record.
I checked the SelectionListener on the table and it is set correctly as "#{bindings.BrowseCategory1.collectionModel.makecurrent}"
Does anyone have any idea why the detail table is not getting updated based on a relationship to the master table?
Thanks,
RaymondHi,
From what you are saying:
1. it's working in application module tester
2. you verified the current row of the iterator and you found that it is stuck on the first row
The problem is then that the selection in the table is not setting the current row in the iterator.
Try to add a custom selection listener where you just execute the "#{bindings.BrowseCategory1.collectionModel.makecurrent}" expression. this is just to make sure that the listener is being called.
Also, the problem might be that the current row is correctly set by the table selection, but later in the life cycle it is being reset. so maybe you can also overwite the methods that set the current row in your VOimpl (again by jsut calling the supper) to check if and when these methods are called.
Regards,
Elias. -
ITunes video reloads itself when no selection changes have been made.
Various video content reloads itself on my devices (iPad Air 2, iPad 2, iPhone 5, and iPhone 4) even though no selection changes have been made (no additional video selected, or deleted) between syncs. This issue turns a sync operation that should take less than a minute into 30 minutes or more! Since this issue has manifested itself across multiple devices, the common factor being my MacBook Pro must be the bad link.
Updates of OS and iTunes have not been enough to repair whatever is wrong.... I hope someone has a simple correction. Apple Support at local store, on phone, and Apple Engineering have not been able to help.
I believe I might need to somehow remove iTunes at a minimum (maybe OS too) from my MacBook Pro and rebuild it with best hopes of this issue finally correcting itself. Does anyone know how to go about a clean removal installation of iTunes and/or OS? Any other suggestions?
Thank you!
MacBook Pro
2.4GHz Intel Core 2 Duo
8GB 1067MHz DDR3
640GB Drive with 95GB free
OSX Yosemite 10.10.2
iTunes 12.1.0.50eeek. there was a hassle with video podcasts and QT 7.0.4 where if a file was corrupted in just the right/wrong way it could crash itunes ... but i hadn't seen one crash an entire PC like that before. (i might have missed reports though.)
is it possible to identify which podcast seemed to be causing you the hassle? or does it seem to happen any time you download any podcast?
Maybe you are looking for
-
Hello. I have a Mac Mini operating Mac OS X 10.7.2. I recently had to move my iTunes Library to a new hard drive. I followed the directions on how to move the library and refind everything yet when I do so what comes up is a mere skeleton of what I h
-
External hard drive & error -61
Downloaded Macfuse, downloaded the ntfs-3g module for it, rebooted. Nothing. I still can't write to the external drive. What's wrong? I
-
Output to DivX file, but as .avi
My client has requested I output a sequence as a DivX (.avi) file. This is for playback to a large screen monitor from a CF card. I downloaded the DivX software, so that now within FCP, under export using QT conversion, there is an option DivX I down
-
Advice for transferring files to computer with same title nam
Hello, I'm looking to purchase a new creative player and i need to thiink about how to transfer my music from my old player to the new one. I assume i would have to transfer music to my computer then from there to the new player. However i tried tran
-
TEXT_CONVERT_XLS_TO_SAP getting error, need help!
Good day, everyone! I am using FM TEXT_CONVERT_XLS_TO_SAP to read in an Excel file. However, I am getting an error, and the error information I'm displaying isn't helping me much. I'm using the widely-found sample code for this FM that is on this f