Eclipse eRCP command framework - Unable to update command label dynamically - eclipse

I've scoured the web for the entire day trying to find an example on how to implement what I read concerning changing a command label dynamically here:
http:// wiki.eclipse.org/Platform_UI_Command_Design#Issue_102_-_Comm ands_implementation_of_label_changing
I have the a command defined in my plugin.xml that uses the suggested schema:
<command
description="Hoping to change my state"
id="my.commandWithState"
name="Command Wtih State">
<state
class="org.eclipse.jface.menus.TextState"
id="NAME"/>
</command>
In my handler, I have tried a lot of variations (including calling "getValue" before trying to set it in hopes of forcing a load to be called), but basically the gist is:
public Object execute(final ExecutionEvent pEvent) throws ExecutionException {
pEvent.getCommand().getState("my.commandWithState").setValue("UPDATED!");
return null;
}
The state value itself is updated, but not persisted. I specified a style of "push" in the menuContribution area of my plugin.xml and the text on the command is always "Command With State" since I did not specify a label (though i expected it to change...)
I'm using Eclipse 3.6 so I assume I have the updates that supposedly allow this from 3.3.
The only way I have been able to set the text on the command ui object is to have my handler implement IElementUpdater like I'm working with a ToggleState. This allows me to change the text a total of 1 time, when I first start the product.
I'm about to tear my hair out.
1) The command "label" is not updated and
2) the state value is not persisted even though TextState extends PersistedState.
What d>_

Related

Codeeffect rule editor allows to select only one action even though there are multiple actions to select from

I have requirements to use codeeffect rule editor for our feature. We have dynamic actions to render in the rule editor which user can select from.
So for that i have created the rule editor using FlexSource type. I tried to configure actions in rule editor by adding FlexMethodInfo for each actions and configured ActionAttributes for each of them.
e.g. the actions are "SetAmount", "SetPercentage" and "SetQuantity" .
It successfully renders the editor and provides the above three options to select from. But which ever option i select it only selects "SetAmount" and shows that in rule editor.
The idea behind FlexSource is to subclass System.Type so that Editor can continue using reflection to enumerate methods, properties, fields, etc.
To do that, there is a minimum number of classes and methods that have to be implemented. The Flex demo shows which those are.
However current version is missing an override for FlexMethodInfo.ToString().
Please add following to your FlexMethodInfo class. Adjust return values to reflect your actual methods and their signatures. The Editor uses ToString() to build hashes and match methods. It follows the same logic as MethodInfo.ToString().
public override string ToString()
{
switch (methodName)
{
case "Concatenate":
return "System.String Concatenate(System.String, System.String)";
case "Register":
return "Register()";
case "Confirm":
return "Confirm(System.String)";
default:
return base.ToString();
}
}
Make sure to get latest NuGet packages for the Editor and Engine. I believe they have released an update that addresses some use cases.

How to read console-output-text by an eclipse-plugin?

I'm trying to write an Eclipse plugin which starts a LaunchConfiguration when an already running LaunchConfiguration prints a user-predefined-string in the console.
Here is a pseudocode example for what I'm looking for:
String check = "Server started and running";
new ConsoleOutputListener(Event event) {
String consoleText = event.getConsoleOutputTextOfAllConsoles();
if(consoleText.contains(check)) {
//launch LaunchConfiguration
}
}
Is there a way to implement the example from above?
Any help si appreciated as always!
You question is a bit unclear as to what exactly you want to do, but possibly you can use the org.eclipse.ui.console.consolePatternMatchListeners extension point to define a pattern match listener on a console.
Something like (from the Eclipse help):
<extension
point="org.eclipse.ui.console.consolePatternMatchListeners">
<consolePatternMatchListener
class="com.example.ExampleConsolePatternMatcher"
id="com.example.ExampleConsolePatternMatcher"
regex=".*foo.*">
<enablement>
<test property="org.eclipse.ui.console.consoleTypeTest" value="exampleConsole"/>
</enablement>
</consolePatternMatchListener>
</extension>
Which matches a regular expression on a particular type of console.
The console support has many extension points for defining different types of extension to the consoles.
If you want to do this more dynamically you can listen for consoles being created using the IConsoleManager:
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
// Existing consoles
IConsole[] consoles = manager.getConsoles();
// Listen for consoles being added/removed
manager.addConsoleListener(console listener);
Text consoles will be an instance of TextConsole you can add a pattern listener using the TextConsole addPatternMatchListener method.

Change the status bar of an ADempiere window

How can I change the status bar text in an ADempiere window in order to show a message when a new record is created?
Also, how can I create a pop-up that appears when a new record is created?
You can put a message in center of window when a new record is created, this function already exists on iDempiere, but on ADempiere you'll need to change code for each docaction, or for each table you code is listening for.
On Idempiere you can check the code of class AbstractADWindowContent.java on package org.adempiere.ui.zk
check this link , line 2104
You can put a status message in status bar in Adempiere using the following method in org.compiere.model.GridTable
/**
* Create and fire Data Status Info Event
* #param AD_Message message
* #param info additional info
*/
protected void fireDataStatusIEvent (String AD_Message, String info)
{
DataStatusEvent e = createDSE();
e.setInfo(AD_Message, info, false,false);
fireDataStatusChanged (e);
}
You will find an example of its use within the same class, when a row is saved via the dataSave(boolean) method. If all goes to plan and record is saved at the end of the method you'll see
fireDataStatusIEvent("Saved", "");
This puts the default “Saved” message see in the application when you click save in any tab.
There are two recommended approaches to customising Adempiere.
Callouts; are used to add complex defaulting & validation in the
User Interface
Model Validators; are used to apply business logic or validation when a number of data model events, such as a record being saved, occur. But, not all changes are happening at the time the UI events are occurring... as with the accounting module, for example, so the model validator mechanisms assume no user interface exists.
Your requirement to have something happen in the UI when a data model event occurs falls between the two. For your requirement it might be easiest just to modify this default message (highlighted above in dataSave()) to display what you would like. But GridTable is at the core of the application so keep in mind that any time you update/upgrade Adempiere in the future you will need to make this modification again!

'Prevented recursive attempt to activate part' when clicking on a marker

I am creating my own GEF based graphical editor. It creates error markers when validation fails and the editor has a gotoMarker method to find and active the marker. This all works.
Only problem is that I get a RuntimeException when double clicking on the marker (when clicking 'GoTo' from the context menu there is no problem)
The message is as follows:
java.lang.RuntimeException: WARNING: Prevented recursive attempt to activate part org.eclipse.ui.views.ProblemView while still in the middle of activating part namespace.myEditorID`
Part of the corresponding stacktrace shows:
at org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3586)
...
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1245)
at org.eclipse.swt.internal.gtk.OS._gtk_enumerate_printers(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_enumerate_printers(OS.java:9296)
at org.eclipse.swt.printing.Printer.getPrinterList(Printer.java:98)
at org.eclipse.gef.ui.actions.PrintAction.calculateEnabled(PrintAction.java:45)
at org.eclipse.gef.ui.actions.WorkbenchPartAction.isEnabled(WorkbenchPartAction.java:123)
...
The complete stacktrace is a bit long, so it is available at pastebin.
This gave me the idea to disable the printing action in ActionBarContributor.declareGlobalActionKeys by removing:
addGlobalActionKey(ActionFactory.PRINT.getId());
This solves the RuntimeException...?!
I do not see the relation between the Printing action and going to the corresponding object after clicking on a marker. Leaving the Printing action disabled, of course, is not a solution.
So what can I do to keep the Printing action available and prevent these RuntimeExceptions?
As a test ,I refer to the url:https://bugs.eclipse.org/bugs/show_bug.cgi?id=154112
and I overrid my EditorPart's setFocus method like:
#Override
public void setFocus() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
}
and then it works well.

oracle jdbc jface wizardpage

I want to create a jface wizard and collect credentials as I go along - password and username on page 1 and then on page 2 I want to display a list I get from an oracle database.
I am using eclipse, and have all the controls in the places I want. On page 2 I put the oracle connection details and sql statement in the createControl method of wizardpage. This seems to fail with a class not found (ojdbc6.jar included in my build path) which I can't decide whether this is an eclipse issue or my code (my code works when it is standalone, not in a wizard)
The failure happens when I start the wizardpage, which it probably will do as I havent got the correct credentials at that point. I couldn't find a method in the wizardpage documentation for running stuff when you enter that wizardpage. Is there a method that runs on entry?
I want to connect to the database to pull down a list to populate a table.
Cheers
David
The createControl method gets called on all pages when the Wizard is opened. You should use createControl only to layout SWT or JFace objects.
You probably want to initialize the JDBC connection when the second page becomes visible. At that point you would then load your list on the page. To do that, override the setVisible method on the second page as follows:
/* (non-Javadoc)
* #see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
*/
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible){
// initialize the jdbc connection here - use a data access object
// use the connection or the DAO to populate your list
}
}
This way the connection will be initialized when the second page becomes visible. Another useful thing to do from the setVisible method is to assign the focus to the right control by calling forceFocus() on the relevant control.