Triggering a browser pane "Edit Value" from a button action

User 306252074b

08-01-2013 16:43:06



Three questions. (Instant JChem 5.11.4)


 


I have a form containing a button and a tabbed panel with three tabs, each containing a single browser pane. I need the button to be disabled when the first tab is selected, but enabled when either of the other two are selected. 




1. How can the tab selection event be made to trigger the on_change action of the button?


2. How can the on_change script determine which of the tabs is selected?




I need the evaluate action of the button to perform the Edit Value action of the browser pane in the selected tab.




3. How can a button press invoke the Edit Value action?


 



ChemAxon 2bdd02d1e5

11-01-2013 18:25:09

I'm sorry, don't know much about the answers. I must ask if this is possible and let you on Monday about the possible solution.

ChemAxon e189db4705

14-01-2013 23:03:04

Hi Ron,


the first two requests can be solved by the following script, but we don't have official APIs for these things. We still have form/widgets API in our plans, but it's not done yet. So please take this as current solution (tested in 5.11.4), it is possible that some methods can change in the future.


The script expects that there is exactly one tabbed widget in the form. It disables the button when the first tab is selected, otherwise it enables the button.


import com.im.df.api.dml.*
import com.im.df.api.support.SelectionDescription
import com.im.ijc.core.api.util.IJCCoreUtils
import com.im.ijc.core.api.views.*
import javax.swing.*
import javax.swing.event.*

init = { widget ->
    def tab = findTab(widget)
    tab.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            widget.browseModeComponent.setEnabled(tab.getSelectedIndex() != 0)
        }
    });    
    widget.browseModeComponent.setEnabled(tab.getSelectedIndex() != 0)
}

destroy = { widget ->
}

evaluate = { widget ->
}

on_change = { widget, button ->
}

JTabbedPane findTab(IJCWidget widget) {
    widgets = widget.form.widgetContainer.getWidgets(true).iterator()
    for (widgetHandle in widgets) {
        if (widgetHandle.widget.factoryId.equals("tabbedPaneWidgetFactory")) {
            return widgetHandle.widget.browseModeComponent
      }
    }
    return null
}

As for the last question: we would need more information what exactly you want to edit. There exists an action inside IJC and this action starts edit of value in the currently selected widget (or cell if widget is table). This is the same like if you press F2. This action is context sensitive and works for currently selected widget.


If you click the button the selection is changed and the button itself is selected then. If you want to edit the value which was selected before the button was clicked it requires some tricky solution. The button would need to remember what widget was selected before the button was clicked. Is this what you want to achieve?


Thanks,


Petr

User 306252074b

16-01-2013 02:08:58

Petr, thanks! That's just what I needed.


For question 3, the widget we want to edit is the browser pane in the selected tab, which is the only widget in the tab. It doesn't matter if some other widget was selected before the button was clicked.


Ron

ChemAxon 2bdd02d1e5

18-01-2013 18:29:18

Ron, how would you image Edit Value action on browser widget to behave? Only edit URL?
This is not supported in the UI...but perhaps it is editable in scripts.
May I ask what benefit it brings to you?


Thanks,
Filip 

User 306252074b

18-01-2013 18:46:03

I would expect it to behave just the way the Browser pane widget currently behaves interactively. When I right-click on the Browser pane, it displays a context menu. One entry on that menu is Edit Value (F2). When I select the Edit Value entry, it displays a panel that lets me select a File from a File browser or type in an URL. The panel shows a preview if it's an image, and provides Cancel and Set Value buttons at the bottom.


I want my button to display that panel in just the same way as clicking on the Edit Value menu entry. The value to me is that having a clearly labeled button reduces the number of clicks the users need to perform the action, as well as the effort needed to train them.


Ron

ChemAxon 99d87cf303

21-01-2013 14:25:42

Hi Ron,

the tweaked button script below, based on Petr's version, starts to edit the first widget on the currently selected tab of the tabbed pane found by findTab() method.

All Petr's remarks about (non-)API are valid here as well.


import com.im.df.api.dml.*
import com.im.df.api.support.SelectionDescription
import com.im.ijc.core.api.util.IJCCoreUtils
import com.im.ijc.core.api.views.*
import com.im.ijc.formview.*;
import javax.swing.*
import javax.swing.event.*

init = { widget ->
    def tab = findTabComponent(widget)
    tab.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            widget.browseModeComponent.setEnabled(tab.getSelectedIndex() != 0)
        }
    });    
    widget.browseModeComponent.setEnabled(tab.getSelectedIndex() != 0)
}

destroy = { widget ->
}

evaluate = { widget ->
    firstComp = findTabContainer(widget).getSceneContainer().getThisDesignerHandles()[0]
    firstComp.startEdit()
}

on_change = { widget, button ->
}

DesignerContainerHandle findTabContainer(IJCWidget widget) {
    widgets = widget.form.widgetContainer.getWidgets(true).iterator()
    for (widgetHandle in widgets) {
        if (widgetHandle.widget.factoryId.equals("tabbedPaneWidgetFactory")) {
            return widgetHandle.widget
       }
    }
    return null
}

JTabbedPane findTabComponent(IJCWidget widget) {
    return findTabContainer(widget).browseModeComponent
}

Let us know if it does not work for you or you meant something different.

Cheers,
- m.

User 306252074b

22-01-2013 21:12:27

Thanks! This is just what I was looking for. I recognize that it uses undocumented API, but perhaps you can include this as a data point when next deciding what API to expose.


Ron