e4 selectionservice - list or single object and adapters [closed] - eclipse-rcp

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a question regarding "best practice" on the e4 selectionservice
1) Handling single and multiple selection
E.g on a tableviewer I can select a single or multiple elements. Depending on that, my active selection is either a object or a collection of objects.
What is the best practice to handle that in my listener?
....selectionService.setSelection(structuredSelection.getFirstElement())
OR
....selectionService.setSelection(structuredSelection.asList())
public void xy (#Optional #Named(IServiceConstants.ACTIVE_SELECTION)
List selection){} --> selection is null if a single element is selected
OR
public void xyz (#Optional #Named(IServiceConstants.ACTIVE_SELECTION) MyObject selection){} --> selection is null if multiple elements are selected
Do I need to implement both methods to handle both scenarios? Why is a single element not packed in a list or vice versa?
2)
How to handle active selections that can be adapted to a target Object?
Do I need to have ISelection parameter and check for the adaptation manually or is there any way the framework can adapt and inject if possible?
Thanks a lot in advance

The normal selection is the actual IStructuredSelection object, not its contents:
selectionService.setSelection(structuredSelection);
public void xx(#Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection)
So you only have one method and it receives all types of selection.
For adaptable objects there is nothing that will do this automatically. Use the org.eclipse.core.runtime.Adapters class to adapt an object:
IFile file = Adapters.adapt(object, IFile.class);

Related

Catalyst FormFu DBIC error - using dot notation in a resultset [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 29 days ago.
Improve this question
I've inherited a Perl Catalyst application that I'm trying to port to a new server. The application uses FormFu with the HTML::FormFu::Model::DBIC module used to load data from a result set.
I have a DBIx table, say MyTable, with an auto-generated Result implementation and a custom ResultSet implementation. In the custom ResultSet implementation there are some subroutines, e.g. sub my_sub, that return filtered subsets of data.
In a FormFu YAML file, the following will fetch all the records from MyTable:
elements:
- type: Select
model_config:
resultset: MyTable
This is equivalent to fetching, in a Controller, $schema->resultset('MyTable'). This executes correctly on both the old server and the new server.
On the old server, I can use dot notation to call the subroutine to fetch the subset of records it returns like so:
elements:
- type: Select
model_config:
resultset: MyTable.my_sub
This is equivalent to fetching in a Controller, $schema->resultset('MyTable')->my_sub. This executes correctly on the old server. On the new server, in FormFu, this throws the error:
Can't find source for MyTable.my_sub at /[...]/HTML/FormFu/Model/DBIC.pm
I've added debugging to the FormFu DBIC.pm module to see if it's doing anything special. The code it calls is $schema->resultset($rs_name); where rs_name is the name given in the resultset parameter, "MyTable.my_sub", and $schema is of type Moose::Meta::Class::__ANON__::SERIAL, which I assume is some kind of wrapper. Within a Catalyst controller, a schema is of type myapp::Schema.
What am I missing? Is there some configuration option I need to set? Some module I need to install? I can't find any documentation or examples that show a FormFu resultset with dot notation, yet on the old server it works.
When I attempted to add logging to the working DBIC.pm file, I discovered that the developer from whom I inherited this application symlinked the module's DBIC.pm file to a custom DBIC.pm file in his own home folder with the extended functionality.

How to automate adding Tagged Value Types and editing of templates in Enterprise Architect [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to automate the following tasks in Enterprise Architect:
Add new tagged Value types
2. Make certain changes to DDL Templates (e.g add system versioning to a table by replacing the DDL Create Table Template for MySQL with another template, that contains a "With System Versioning" clause)
Is there a way to achieve this via scripting (https://sparxsystems.com/enterprise_architect_user_guide/15.0/automation/automation_interface.html), by writing an Add In (https://sparxsystems.com/enterprise_architect_user_guide/15.1/automation/addins_2.html) or by using MDG Technologies (https://sparxsystems.com.au/enterprise_architect_user_guide/14.0/modeling_tools/mdgtechnologies_2.html) for Enterprise Architect?
Thank you in advance for all comments, answers and ideas!
Adding tagged value types is definitely possible.
I use this code in my Model wrapper
This is C#, but the translation to any other supported language such as VBScript is trivial.
public void addTaggedValueType(string tagName, string tagDescription, string tagDetail)
{
global::EA.PropertyType taggedValueType = (global::EA.PropertyType)this.wrappedModel.PropertyTypes.AddNew(tagName, "");
taggedValueType.Description = tagDescription;
taggedValueType.Detail = tagDetail;
taggedValueType.Update();
}
I don't think the API has a feature to update DDL templates directly, but you can deploy those with an MDG.
And you can include an MDG into your add-in. See this add-in class for an example
Normally tagged value types are also distributed in an MDG and not created directly by an add-in.

When should I use a Scala class and when to use Scala object in IDE? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have seen many cases where we can create a Scala project with only Scala object file and have our code inside it without the need of having a Scala class file.
I am currently working in a project where the Developer has written the code in the Scala object file (which acts as an object) instead of writing in a class file. To be more precise here is the screen shot of my IDE which shows that the code is written in an object file.
I want to know significance of writing a code in a Scala class and object file. What is the ideal scenario to use them?
There is a similar post available here which shows only the difference between a class and an object however I want to know when should I consider to use a Scala class and when to use a Scala object?
Use class when you want to create the same data structure multiple times with difference values. For example, a class could represent a row of data in a database application, or a client request in a web server.
Use object when you only need a single copy of the data structure in your program. For example, the command line for a program, or a data cache.
Classes can have short lifetimes, so use them for data that comes and goes. Objects always last until the program completes, so use them for data that needs to be available permanently.
It is reasonably straightforward to convert an object into a class, so start with an object unless you know that you are going to need multiple instances of the data.
If you just want to group similar functions or data (in a namespace), put it in an object.
If you want are writing code for a software library, use classes that can be created and deleted as required.
Note that this applies to top-level objects. An object can also be used as a class member or as a local value, but in this case it operates like a class in that it can have multiple instances and may have a limited lifetime.
An object is something that you can only have one in your program. It's most of the time used to contain functions or objects that don't change much. It's the equivalent of static in other languages
For instance:
object StringUtils {
val LF = "\n"
def toUpperCase(str: String) = str.toUpperCase()
}
// usage
StringUtils.toUpperCase("foo")
On the other hand, a class is something you can create with new. You can have several instances of a class in your program
class StringContainer(str: String) {
def toUpperCase() = new StringContainer(str.toUppercase())
}
// usage
val myString = new StringContainer("foo")
myString.toUpperCase()
For more detailed examples you can look at the scala documentation:
https://docs.scala-lang.org/tour/classes.html
https://docs.scala-lang.org/tour/singleton-objects.html
https://docs.scala-lang.org/tour/case-classes.html

How to use variables in Matlab App Designer in all callbacks [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have different callbacks in an Matlab App Designer App. In my case several buttons. I need to use the same variables for that.
I only get an error when using a variable I created in one Callback in another...
I think I got your problem.
The easiest way is in beginning to create a new property (red button on the top left in EDITOR) and use it as a variable throughout the code.
Be careful to use app.variablename to address the variable.
If your code is already finished and you just discovered that error, you can set properties for only the variables you need to exchange and then get them like this:
set property:
properties (Access = private)
varone %first variable
vartwo % second variable
...
end
get Data for Exchange:
varone = app.varone; %(now you can use varone instead of app.varone)
make it public again at the end of your callback:
app.varone = varone;

Compile error when setting class in VBA [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I copied code from here but I'm getting an error when trying to run the code.
The problem would be in:
Public NextItem As New queueItem
and the error message is:
user-defined type not defined
Is my VBA version not right to do this or am I doing something wrong?
You probably mean this link? The one you provided has the alternative implementation (with arrays, not with references).
I got it to work for me. Steps:
Right click on the VBA project file name, and go to Insert-> Class Module:
Click F4. The Properties window appears. Then go to the class Name and change it to Queue:
Copy and Paste the Queue Class code you found at the web site. Repeat the previous and this step for the QueueItem class (i.e., insert a Class Module, name it QueueItem and copy the code inside that class module).
This time, insert a Module using the same process (not a Class Module, but rather a simple Module). You do not need to give your module a name, Module1 will be OK.
Copy the Sub TestQueue() inside the module and run it. It should work. If you use Option Explicit on your module, you will get an error that element is undefined. So we need to define it: Dim element as Variant, under the first few Dim statements of the subroutine. Then it should run.
The above worked for me, let me know if I can be more precise, or send the file to you.