I am building an iGoogle like "dashboard" for our application with silverlight 4.
Each users dashboard (which snapins and their positions) will be stored in the database. Each snap in is a user control, for example... AwesomeSnapin.xaml.
On the dashboard page in silverlight I am retrieving the users dashboard which is a collection of snapin objects which include the information on the snapin. I can store the name of the page or the class or whatever is needed.
I have the following code which loops through the collection of snapins to add them to the dashboard page. In testing I have just hard coded a single snapin item. Here is the prototype code:
foreach (var UserSnapin in op.Entities)
{
UserControl uc = new AmsiSL.eFinancials.BudgetCheck();
Canvas.SetLeft(uc, UserSnapin.PositionLeft);
Canvas.SetTop(uc, UserSnapin.PositionTop);
Layout.Children.Add(uc);
MessageBox.Show(String.Format("Added {0}",UserSnapin.Snapin.Name));
}
The above works fine... but of course adds the BudgetCheck snapin for every item that is defined for the users dashboard. Of course the messagebox is for debugging purposes only.
How would I change line 3 of that to load the user control class (using classname or xaml path whichever is better) based on the data in the collection.
I'll assume for the moment that UserSnapin.Snapin.Name in this case is "BudgetCheck" and that all Snapins are found in the AmsiSL.eFinancials namespace. I'll also assume that your Usercontrols are compilied in to the same application assembly. You can use this code:-
foreach (var UserSnapin in op.Entities)
{
Type snapInType = Assembly.GetExecutingAssembly()
.GetType("AmsiSL.eFinancials." + UserSnapin.Snapin.Name);
UIElement snapIn = (UIElement)Activator.CreateInstance(snapInType );
Canvas.SetLeft(snapIn , UserSnapin.PositionLeft);
Canvas.SetTop(snapIn , UserSnapin.PositionTop);
Layout.Children.Add(snapIn);
}
IF the snapins are an a library instead you can probably use the Type.GetType(string) static method to resolve the value for snapInType but you would need to know the assembly name as well.
Related
I have a WindowsForm application having all text(On form labels/buttons/other controls) written in the Norwegian language. I want to convert all text in English using localization. Is there any way in Devexpress where we can convert all text into English without writing the meaning of every text in a resource file manually?
For example:- In the attachment, "Brukernavn" is hardcoded on a label. I want to auto-convert it into English without assigning its value in English-ResourceFile. What should be the approach in Devexpress localization?
I'm not aware of any Devexpress method to do this. A good solution would be to actually do the work of building a localisation file for English which would work like following.
Add a InternationlisationLayer to your application.
This layer
scours the application to locate all Controls you would possible want
to translate.
After finding all Controls you have to match their
Text values to the translated text.
After finding a matching English
text you will have to replace the Text Property on these Controls.
If you want to avoid building a proper Localisation system a far easier solution is explained below.
Make a List of type and fill it with all control texts you want translated.
Translate the strings and add format them as such that you have a Dictionary of type (where Key would be the original text and Value being the translated text).
At application Start get a list of all Controls you want to translate and do something like the following:
public static IEnumerable<System.Windows.Forms.Control> GetAllControlsOfType(this System.Windows.Forms.Control control, Type type)
{
var controls = control.Controls.Cast<System.Windows.Forms.Control>();
return controls.SelectMany(ctrl => GetAllControlsOfType(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
public void DoTranslation()
{
var ctrls = this.GetAllControlsOfTypes(new List<Type>() { typeof(Label), typeof(Button) });
foreach (var ctr in ctrls)
{
var element = dict.FirstOrDefault(i => i.Key == ctr.Text);
ctr.Text = element.Value;
}
}
Hi I am a newbie in CodenameOne am now creating a eCommerce app using CodenameOne resource editor ,I have used multilist for displaying products . I have checked the checkbox feature wherein I got the checkbox for all my items .My question here is by code in statemachine how do I get the name of product checked by the user and how to get whether the checkbox is checked or not .I tried implementing findMultiList().getSelected() but it returns always true if I check r uncheck.
Please help me also it would be great if you could tell me how to integrate google drive in my project because I need to pull data from excel sheet and populate it in the list.
You need to get the model and traverse the elements within it:
ListModel<Map<String, Object>> model = (ListModel<Map<String, Object>>)findMultiList(c).getModel();
ArrayList<Map<String, Object>> items = new ArrayList<>();
for(int iter = 0 ; iter < model.getSize() ; iter++) {
Map<String, Object> current = model.getItemAt(iter);
String checked = (String)current.get("emblem");
if(checked != null && "true".equals(checked)) {
items.add(current);
}
}
I haven't tried this code but it should work. Notice that the name "emblem" is the default name used for the MultiButton/MultiList but you can change it to be anything.
You can place a break point on the for loop and inspect the map elements as you traverse them to see how this works.
Codename One doesn't have dedicated support for google drive api yet...
However, it does support Firebase (noSQL, so no table type data)
THis means you'll have to work with variable pairs.
There are resources for table databases, though :
https://www.codenameone.com/javadoc/com/codename1/db/Database.html
check out these libraries
https://github.com/shannah/cn1-data-access-lib
(Accessing data from web, sqlite support)
https://github.com/jegesh/cn1-object-cacher
(cache from web db)
These resources should help; good luck with your development :)
I am facing an issue where my graph is tree layout and looks fine initially. However, if I choose to change GraphSource upon user input/ clicks using PopulateGraphSource like in the OrgChart example, I get all the nodes stacked on top of each other with no links and all in corner.
I tried resetting graphSource by creating a new one
this.graphSource = new GraphSource();
I also tried to use the Clear method for GraphSource. Neither did solve the problem, I keep having the same issue.
I am using
ObservableCollection<Node> hierarchicalDataSource;
to fill up my GraphSource object.
All I do is create a new one and then call
PopulateGraphSource();
method.
Similar issues: question in telerik support , telerik support different question
Try calling the Layout method on the diagram control. Here is a little fragment of code
TreeLayoutSettings settings = new TreeLayoutSettings()
{
TreeLayoutType = TreeLayoutType.TreeDown,
VerticalSeparation = 60,
HorizontalSeparation=30
};
if (this.diagram.Shapes.Count > 0)
{
settings.Roots.Add(this.diagram.Shapes[0]);
this.diagram.Layout(LayoutType.Tree, settings);
this.diagram.AutoFit();
//this.diagram.Zoom = 1;
}
I have modular project structure, like this:
./main.py
./app.yaml
../articles
.../__init__.py
.../models.py
../blog
.../__init__.py
.../models.py
../comments
.../__init__.py
.../models.py
I have defined models in file models.py for each package (this is application). I have defined next models for "comments" application:
class Comment(db.Model):
author = db.UserProperty(auto_current_user_add=True)
title = db.StringProperty(default="Title")
text = db.TextProperty("Message", default="Your message")
# references to any model
object = db.ReferenceProperty()
and in "articles" application I have defined next models:
class Article(db.Model):
author = db.UserProperty(auto_current_user_add=True)
title = db.StringProperty(default="Title")
text = db.TextProperty("Message", default="Your message")
1) On first loading of page - I create new article:
from articles.models import Article
article = Article(title="First article", text="This is first article")
article.put()
2) On second loading of page I create new comment:
from articles.models import Article
from comments.models import Comment
article = Article.get_by_id(1)
comment = Comment(title="First comment", text="This is first comment")
comment.put()
3) On thind loading of page, I want to see all comments for all articles, blogs, and other objects in whole datastore:
from comments.models import Comment
comments = Commen.all()
for comment in comments:
# print comment and article title
print "%s: %s" % (comment.title, comment.object.title)
Actual result: "KindError: No implementation for kind 'Article'"
Expected result: automatically detect object type for reference and load this class
See more on: http://code.google.com/p/appengine-framework/issues/detail?id=17
Project need your help!
In order to be able to return entities of a given kind, App Engine has to be able to find the Model class for it. There's no mechanism built in for doing so, because all it has to look it up with is the entity kind, which can be any arbitrary string.
Instead, import the modules containing the models you may reference from the module containing the Comment model. That way, any time you can perform a query on Comment, all the relevant models are already loaded.
In my project GAE framework I have solve this issue. On the first page loading I have load all models in memory.
What if we have models with the same name, for example Comment model in "blog" and "board" applications? In this case we have automatically add prefix for models for the King of this model. In result we have the different names for models in different applications: BlogComment and BoardComment.
You can learn more in source code to understand how we do this implementation.
When populating my treeview I would like to use the same images that I use in my toolbar etc which are stored in a resource file.
The treeview seems to on accept images via an image list.
I was thinking of reflecting and adding the resources to an image list on load...
How do you guyz n girlz generally do this?
Just for completeness, that "sledge hammer" approach to add all images from a resource
foreach (var propertyInfo in
typeof(Resources).GetProperties(BindingFlags.Static | BindingFlags.NonPublic)
.Where(info => info.PropertyType == typeof (Bitmap))) {
mainImageList.Images.Add(
propertyInfo.Name,
(Bitmap)propertyInfo.GetValue(null, null));
}
I usually have an image list that I populate using images from the resource file. This can easily be done when initializing the form.
Example (with three images in Resources.resx, called one, two and three):
private void PopulateImageList()
{
_treeViewImageList.Images.Add("one", Resources.one);
_treeViewImageList.Images.Add("two", Resources.two);
_treeViewImageList.Images.Add("three", Resources.three);
}