Editor specific command state - eclipse-plugin

I have created a command and a handler that interacts with text editors (objects implementing ITextEditor). For each editor that the handler interacts with I'd like to store some data that the handler has access to.
What is the best way to do this?
Information about my specific problem
My command modifies the selection of text of the active editor. When the command is executed I want to store information about the previous selection. Another command should be able read this information and restore the previous selection.
Thoughts and observations
If one handler instance was created for each editor that would solve my problem. Is there a way to achieve this?
I've looked at the source code of the Java editor, trying to understand how things work there. The editor stores references to action objects. Since I can't create new fields for my command I can't use the same approach.
I've looked at the <state> plugin.xml tag, but I don't understand how to get one piece of state for each editor. But maybe there is a way?
I could manually maintain a map from editor to state object, and maybe register a listener for when editors are opened and closed. But I would prefer if there was a simpler way, where I didn't have to do this myself.
Maybe actions (IAction) could be used? But aren't they an old mechanism that has been substituted by commands?
I could maybe manually set an IAction object which as an reference to the stack using the ITextEditor.setAction.

If you are using Eclipse 4 you could use the transient data of the MPart object associated with the IEditorPart.
To get the MPart from an IEditorPart use:
MPart part = editor.getSite().getService(MPart.class);
Map<String, Object> transientData = part.getTransientData();
You can store anything you like in the transient data, use a key unique to your handler for the map key. The data is discarded when the editor closes.

Related

Not open popup for action

I'm using Apache Isis v1.16.2.
I created an edit action but when my action is invoked Isis opened the associated form into a popup. I tried to set the property isis.objects.editing to false but in this way the user have to edit each property and click 'Ok' for each one. Which action Isis call to create default edit form? My goal is: the user open the form, edit all properties and click 'Save' once. Is there a way to do it? Thanks in advice.
currently the only way to do this is with an action that takes all the arguments for the properties that you want to change.
We do have a JIRA ticket to allow such an action be associated with a fieldset rather than a property, so that when invoked would "replace" the fieldset (similar to how, today, an action associated with a property temporarily replaces just that one property).
That said, the Apache Isis framework is not intended to be a simple CRUD framework (even though people often mistake it as that). Rather than let the end-user edit all properties in a single operation, instead identify why the fields need updating. This will lead to a richer domain model that encapsulates meaningful business rules, rather than being some sort of glorified spreadsheet.
Still, the Wicket viewer is extensible though. If you absolutely need an edit form yourself, see http://isis.apache.org/guides/ugvw/ugvw.html#_ugvw_extending_replacing-page-elements.
Alternatively, for that particular use case, consider developing a custom viewer and leverage Isis' REST API.
HTH

undo for non textbox controls

new to .net coming from vba decided to rewrite a management app using vb.net and SQL Server.
Started writing the base library for my application.
I created custom controls to use in my application that would expose a Zoom function, background color for the current active control a .modified property similar to the one available in textbox and some extra other properties (SQLTableName, SQLColumnName, ...) to enable iterating through a container (form) for modified controls and Update/Insert into a SQL table via a SQLProcessClass.
Concurrently I'd like to also implement a simple undo functionality.
My first idea was to add a PrevValue variable set in the OnEnter event if the Modified property is False, exposing an OldValue property and an Undo method in the custom controls.
However I found that the TextBoxBaseClass already exposes an Undo method and that there is an UndoEngineClass available.
Unfortunately the vs helpfile does not give examples of how to use / implement that class.
Could someone explain the usage of the UndoEngine class non-textbox controls and if it is advisable to use it or rather write my own (as I first intended to do - I also found some interesting articles about undo/redo classes) but why reinvent the wheel in case .net already provides a class for it.
thks

How to check for the active Application?

I made a VBA-Macro, activated via a Ribbon-Button for exporting selected Mails into a certain folder.
I'd like to make this Macro available in Word and Excel (for exporting doc/xls) into the same folder-structure.
Is it possible to check for the active application and then decide if a Mail(s)-Export or a simple Doc/Xls-Export should be done?
If you are working with multiple Applications probably the easiest way to identify one would be to use Application.Name property.
If you happen to have passed an object of some type that has the .Application property you can also call that. Refer to this post for details.
Also, with most MS-Office objects you can go up the hierarchy using the .Parent property to get all the way up to the Application, ie. .someObj.Parent.Parent.Parent.Application.Name

Using querySaveDocument to additional information

We are trying to save some additional information with a document using the QuerySaveDocument event. However it seems that it is not being triggered at all.
<xp:executeScript script="#{javascript:setField(document1, 'cCustAddr1_fi', 'test');}">
</xp:executeScript>
This is our basic script. All the setField() method does is use replaceItemValue to try and set the field. However it seems that QuerySaveDocument is not even being triggered since we can write pretty much anything and the document will still save without problem, even if it would be impossible to execute.
We have also tried using a simple document1.getDocument().replaceItemValue() script, but again I dont think it even attempts to execute. Our documents save perfectly fine too,
Do you see any reason for this, are we doing our saving wrong, or should we be attaching data onto the document in another way?
Thanks.
Your other question on Unplugged (Using other dialog controls in iOS) suggests that you are using the Unplugged Mobile Controls project.
If that is correct then my comment above applies - the querySaveDocument event won't get fired . You can look at the code in UnpSaveDocument.xsp and possibly add your own SSJS code to that.
Alternatively, if you want an additional item created on your back-end Notes document then you should just be able to add a hidden field to the UnpFormEditor that is bound to the document1 data source and using the relevant item name you want.

Create a shared copy and paste menu for my grids

I have 20 or so grids in my application suite. I'd like to create a global copy/paste context menu which I can bind to every single grid rather than code in each form.
I am unsure what is the best way to achieve this, I have started to create a class with my menu in it, but get stuck at the point of adding the actual menu options. For example I know I'll need to call a "copy" event, but I also know I'll need to tell it what I am copying, and I cannot see how that is done in vb.net when you can only add the address of a method minus parameters.
e.g.
.MenuItems.Add("Copy Cell", New System.EventHandler(AddressOf CopyCell))
Obviously I want "CopyCell" to only be coded in one place as well, rather than repeated in each form. I will always be copying the same object (SelectedCellCollection).
I am not sure how to make the menu have an event with parameters, or how to make it "know" that I want to always copy the selected items. I'm aware that I'd have to do some coding in the form but just trying to work out the way to minimize it.
I have created my own context menu class (via inheritance) with specific copy and paste functionality / options tailored to the grid I am using. It works fine and only needs one line of code per form/grid to activate.