Skip to main content



      Home
Home » Eclipse Projects » Sirius » [Properties view] Use Java services in properties view (to get input from the user)
[Properties view] Use Java services in properties view (to get input from the user) [message #1736201] Mon, 27 June 2016 09:05 Go to next message
Eclipse UserFriend
Hi,

I use Java services in the Diagram model for various purposes and
though I could use them in the Properties View, too. The idea was to
add a Set model operation with an aql expression that referred to the
Java service. Something like aql: stringInput("Enter type"), but it
doesn't seem to work. It may be it's because the service is defined on
the Diagram model, which is outside the scope of the Properties view
description? Anyhow, using Java services in this way would clearly be
useful also in Properties view descriptions. Is that planned, or should
I file an issue?

Hallvard
--
Hallvard Trætteberg (hal@xxxxxxxx.no)
Associate Professor, IS group, Dept. of Computer and Information
Science at the
Norwegian Univ. of Science and Technology
Re: [Properties view] Use Java services in properties view (to get input from the user) [message #1736202 is a reply to message #1736201] Mon, 27 June 2016 09:20 Go to previous messageGo to next message
Eclipse UserFriend
Actually it did work, there just was a minor bug... I've added the
service class below. DialogInputServices class is declared in the
Diagram model. The expression I used was aql: self.stringInput('Enter
type'). Note how the methods has a first argument ignore of type
EObject, that picks up, but ignores the context object.

Hallvard

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;

public class DialogInputServices {

private static String stringInput(String title, String prompt, String
initial, String def, String pattern) {
InputDialog dialog = new
InputDialog(Display.getCurrent().getActiveShell(), title, prompt,
initial, new RegexValidator(pattern));
return (dialog.open() == Window.OK ? dialog.getValue() : def);
}

public static String stringInput(EObject ignore, String title, String
prompt, String initial, String def, String pattern) {
return stringInput(title, prompt, initial, def, pattern);
}

public static String stringInput(EObject ignore, String title, String
prompt) {
return stringInput(ignore, title, prompt, null, null, null);
}

public static String stringInput(EObject ignore, String prompt) {
return stringInput(ignore, "Input String", prompt);
}

private static class RegexValidator implements IInputValidator {

private final String pattern;

public RegexValidator(String pattern) {
this.pattern = pattern;
}

@Override
public String isValid(String newText) {
return (pattern == null || newText.matches(pattern) ? null : "Input
does not match " + pattern);
}
}
}

On 2016-06-27 13:05:28 +0000, Hallvard Trætteberg said:

> Hi,
>
> I use Java services in the Diagram model for various purposes and
> though I could use them in the Properties View, too. The idea was to
> add a Set model operation with an aql expression that referred to the
> Java service. Something like aql: stringInput("Enter type"), but it
> doesn't seem to work. It may be it's because the service is defined on
> the Diagram model, which is outside the scope of the Properties view
> description? Anyhow, using Java services in this way would clearly be
> useful also in Properties view descriptions. Is that planned, or should
> I file an issue?
>
> Hallvard


--
Hallvard Trætteberg (hal@xxxxxxxx.no)
Associate Professor, IS group, Dept. of Computer and Information
Science at the
Norwegian Univ. of Science and Technology
Re: [Properties view] Use Java services in properties view (to get input from the user) [message #1736231 is a reply to message #1736202] Mon, 27 June 2016 11:30 Go to previous message
Eclipse UserFriend
hi

I guess, i have anything else to add.
It is normal to have a EObject parameter as it corresponds to the
instance of object the method is called on (here self) [1].

Regards
Laurent

[1]
http://help.eclipse.org/mars/topic/org.eclipse.sirius.doc/doc/specifier/general/Writing_Queries.html?cp=69_2_8_7#service_methods

Le 27/06/2016 à 15:20, Hallvard Trætteberg a écrit :
> Actually it did work, there just was a minor bug... I've added the
> service class below. DialogInputServices class is declared in the
> Diagram model. The expression I used was aql: self.stringInput('Enter
> type'). Note how the methods has a first argument ignore of type
> EObject, that picks up, but ignores the context object.
>
> Hallvard
>
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.jface.dialogs.IInputValidator;
> import org.eclipse.jface.dialogs.InputDialog;
> import org.eclipse.jface.window.Window;
> import org.eclipse.swt.widgets.Display;
>
> public class DialogInputServices {
>
> private static String stringInput(String title, String prompt,
> String initial, String def, String pattern) {
> InputDialog dialog = new
> InputDialog(Display.getCurrent().getActiveShell(), title, prompt,
> initial, new RegexValidator(pattern));
> return (dialog.open() == Window.OK ? dialog.getValue() : def);
> }
>
> public static String stringInput(EObject ignore, String title,
> String prompt, String initial, String def, String pattern) {
> return stringInput(title, prompt, initial, def, pattern);
> }
>
> public static String stringInput(EObject ignore, String title,
> String prompt) {
> return stringInput(ignore, title, prompt, null, null, null);
> }
>
> public static String stringInput(EObject ignore, String prompt) {
> return stringInput(ignore, "Input String", prompt);
> }
>
> private static class RegexValidator implements IInputValidator {
>
> private final String pattern;
>
> public RegexValidator(String pattern) {
> this.pattern = pattern;
> }
>
> @Override
> public String isValid(String newText) {
> return (pattern == null || newText.matches(pattern) ? null :
> "Input does not match " + pattern);
> }
> }
> }
>
> On 2016-06-27 13:05:28 +0000, Hallvard Trætteberg said:
>
>> Hi,
>>
>> I use Java services in the Diagram model for various purposes and
>> though I could use them in the Properties View, too. The idea was to
>> add a Set model operation with an aql expression that referred to the
>> Java service. Something like aql: stringInput("Enter type"), but it
>> doesn't seem to work. It may be it's because the service is defined on
>> the Diagram model, which is outside the scope of the Properties view
>> description? Anyhow, using Java services in this way would clearly be
>> useful also in Properties view descriptions. Is that planned, or
>> should I file an issue?
>>
>> Hallvard
>
>
Previous Topic:[PropertiesView] Has anybody a working example for the select option in the new Properties View?
Next Topic:Bug with diagram saving (and opening)
Goto Forum:
  


Current Time: Tue Apr 15 01:05:30 EDT 2025

Powered by FUDForum. Page generated in 0.02727 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top