Can I override the dijit/form/_AutoCompleterMixin to match any part of string not only beginning string? - autocomplete

I have a customized single select on ibm bpm using the dojo toolkit.
It is implemented from dijit.form.FilteringSelect which extends dijit.form.ComboboxMixin which extends dijit/form/_AutoCompleterMixin where if user types in a partial string, highlight the entries in the drop down list that start with that partial string
I need if user types in a partial string, highlight the entries in the drop down list that CONTAIN with that partial string.
So Is it possible I override this dojo component?
and what are the risks?

You can enable substring search when using FilteringSelect component as follows:
var obj = new FilteringSelect({
queryExpr:"*${0}*", //enables substring search
autoComplete:false, //prevents autocomplete
//other arguments
});
Here is a working sample: https://codepen.io/carlosnantes/pen/JjPXYeJ

Related

yup - is there any way to set the default value for a string field to be something without defining it for each one

I want that every time I use yup.string(), it will add a specific default value for it
for example:
const schema = yup.object({
text: yup.string()// I want it to also do .default('some string') in the background,
});
or - another option - is there any way to set the default value after creating the scheme? something like setDefault('text', 'some string')
The closest solution I came across to solve your issue is extending your string with a custom method that implements your needs. To do that you need to use addMethod from yup:
import { addMethod, string } from 'yup';
addMethod(string, 'append', function append(appendStr) {
return this.transform((value) => `${value}${appendStr}`);
});
Now, you can use your custom method (append) and apply it to any string you want:
string().append('~~~~').cast('hi'); // 'hi~~~~'
If you want to add the custom method to all your schema types like date, number, etc..., you need to extend the abstract base class Schema:
import { addMethod, Schema } from 'yup';
addMethod(Schema, 'myCustomMethod', ...)
Extra
For Typescript
In your type definition file, you need to declare module yup with your custom method's arguments and return types:
// globals.d.ts
import { StringSchema } from "yup";
declare module 'yup' {
interface StringSchema<TType, TContext, TDefault, TFlags> {
append(appendStr: string): this;
}
}
Unknow behavior for transform method
While I was trying to extend the functionality of the date schema with a custom method that transform the date that user enters from DD-MM-YYY to YYYY-MM-DD, the custom method broke after I used it with other methods like min, max for example.
// `dayMonthYear` should transform "31-12-2022"
// to "2022-12-31" but for some reason it kept
// ignoring the `cast` date and tried to transform
// `1900` instead!
Yup.date().dayMonthYear().min(1900).max(2100).required().cast("31-12-2022") // error
To work around this issue, I appended my custom method at the end of my schema chain:
Yup.date().min(1900).max(2100).required().cast("31-12-2022").dayMonthYear() // works as expected
This issue is mentioned in this GH ticket which I recommend going through it as it's going more in-depth on how to add custom methods with Typescript.
References
addMethod
Extending built-in schema with new methods
Example of addMethod in Typescript (GH ticket)

How to set the background colour of elements according to their visibility modifier in Eclipse?

I'd like to set the background colour of fields and methods (on the first level) according to their visibility modifier in Eclipse.
For example private fields and methods should get a red background, while public fields and methods get a green background:
Is there a way to configure this in Eclipse?
To get this sort of a colored background, you need to use Markers and MarkerAnnotationSpecification. You will find how to use them here: http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/
As for how to find the private, public fields, you need to use the JDT plugin and the AST parser to parse the Java file and find all the information that you want. I am adding a small code snippet to get you started on this.
ASTParser parser = ASTParser.newParser(AST_LEVEL);
parser.setSource(cmpUnit);
parser.setResolveBindings(true);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
AST ast = astRoot.getAST();
TypeDeclaration javaType = null;
Object type = astRoot.types().get(0);
if (type instanceof TypeDeclaration) {
javaType = ((TypeDeclaration) type);
}
List<FieldDeclarationInfo> fieldDeclarations = new ArrayList<FieldDeclarationInfo>();
// Get the field info
for (FieldDeclaration fieldDeclaration : javaType.getFields()) {
// From this object you can recover all the information that you want about the fields.
}
Here cmpUnit is the ICompilationUnit of the Java File.

wysihtml5 editor - how to simply add a class to an element?

I'm loving wysihtml5 but I can't find any documentation about something as simple as adding a class to an element.
Basically what I'm looking for is a way to allow 2 different variations on the blockquote element:
blockquote.pull-left
blockquote.pull-right
(where each class specifies different style attributes)
So ideally I'd like to create 2 additional toolbar buttons that allow me to not only use the formatBlock command (to wrap the selection withing a blockquote element) but also specify the blockquote's class.
Any idea?
Try adding a custom function like this into a separate custom.js file for clarity:
wysihtml5.commands.custom_class = {
exec: function(composer, command, className) {
return wysihtml5.commands.formatBlock.exec(composer, command, "blockquote", className, new RegExp(className, "g"));
},
state: function(composer, command, className) {
return wysihtml5.commands.formatBlock.state(composer, command, "blockquote", className, new RegExp(className, "g"));
}
};
And then in your toolbar pass the class name through like this assuming the class is "pull-left":
<a data-wysihtml5-command="custom_class" data-wysihtml5-command-value="pull-left">Pull left</a>
You will also have to add any custom classes into the "whitelist" by going to the advanced.js file and adding them there under classes, otherwise the classes will be stripped out when you save.

Display all enums from an EMF model in a CheckBoxTable ?

I am trying to display a CheckBoxTable in an Eclipse page which enables the user to select any one of a number of items - the items that are available come from an EMF model and are enums.
I've got the content provider and the label provider set up correctly (I think) but I can't figure what to use to set the input in order to display the full list of enums.
So say my model has an enum called MyEnum which has values of ONE, TWO and THREE - I want to be able to display all three of those enums to the user as check boxes.
I need to call setInput(...) on the viewer but what do I pass into it to get those enums?
Although I've never done it for a CheckboxTableViewer, I have set an EEnum as the source of values for other StructuredViewer classes like ComboViewer. What I did was create a custom IStructuredContentProvider that is a subclass of ArrayList and takes the EEnum as a constructor argument (call this class EEnumContentProvider). In the constructor, I iterate over the EEnum's getELiterals() and call add() on each of their getInstance() values. Like this:
public EEnumContentProvider(EEnum source) {
List<EEnumLiteral> literals = source.getELiterals();
for (EEnumLiteral aLiteral : literals) {
add(aLiteral.getInstance());
}
}
You can easily implement IStructuredContentProvider.getElements(Object) by using returning the result of toArray() and you don't care about IContentProvider.setInput() because the contents aren't based on the input, they're static.
Then you can set an instance of EEnumContentProvider as the content provider for the viewer.
Simply you need to get the literals and add them to the control as follows:
/* Populate the Combo Box with the Literals */
EEnum cFEnum = Package.Literals.LITERAL_ENUMERATION;
/*
* Add an EMPTY item value so that the user can disable the specific
* feature
*/
this.cmbNames.add( EMPTY_STRING );
/*
* Add the Enumeration Literals to the
* appropriate SWT Combo widget.
*/
for (int i=0; i<cFEnum.getELiterals().size(); i++){
this.cmbNames.add( cFEnum.getEEnumLiteral( i ).toString() );
}
cFEnum = null;
String[] sortedTypes = this.cmbNames.getItems();
Arrays.sort( sortedTypes );
this.cmbNames.setItems( sortedTypes );

GWT messages interface with lookup support

I'm working on a new application and i need to make a messages interface with lookup, using the key to find the value (like ConstantsWithLookup, but capable to receive parameters). I have being investigating Dictionary class functionality but it lacks message customization through parameters.
With ConstantsWithLookup i can make the following:
myConstantsWithLookupInterface.getString("key");
and get something like:
Field must be filled with numbers
But i need to do this:
myMessagesWithLookupInterface.getString("key", "param1", "param2",...);
and get something like:
Field _param1_ must be filled with numbers greater than _param2_
I have no clue how to do this.
Use GWT regular expressions:
//fields in your class
RegEx pattern1 = RegEx.compile("_param1_");
RegEx pattern2 = RegEx.compile("_param2_");
public String getString(String key, String replace1, String replace2){
// your original getString() method
String content = getString(key);
content = pattern1.replace(content,replace1);
content = pattern2.replace(content,replace2);
return content;
}
If your data contains Field _param1_ must be filled with numbers greater than _param2_ then this will replace _param1_ with content of string replace1.