in my test application, the ModuleCatalog is populated from the specified directory with all my modules in it. What I'd like to do is to add the name of all these moudles to a Menu as menuitems, e.g. if I have 3 modules in the directory, the menu will show 3 menuitems with the name of modules.
I thought I can get the list of ModuleInfo like below. But miList shows 0 count. What is the problem here?
protected override void ConfigureModuleCatalog()
{
DirectoryModuleCatalog directoryCatalog = new DirectoryModuleCatalog()
{ ModulePath = #".\Modules" };
((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog);
List<ModuleInfo> miList = ModuleCatalog.Modules.ToList() ; // returns 0 items ??
}
The list of the modules will be populated after InitializeModules has run later on during the bootstrapping process. InitializeModules calls ModuleManager.Run().
You could populate your menu in your shell after it has loaded (get ahold of the ModuleCatalog through the ServiceLocator.Current) You could also populate your menu in the OnPopup event.
Related
I m trying to grasp the purpose of the following 3 concepts ( classes ) that are core functionalities in Idempiere/Adempiere.
Based on code description
I do understand that GridTab have the state of the model representing the ad_tab which is the ViewModel Part of any ad_table. simple said we will found the data bound to the ad_table.
First, for the GridField I believe is the model of the view, if I can abuse it is like the the DOM state: what do we have as fields, values of fields and events, I believe that is template view centric.
Dicovering this two ( if I m not mistaken in my analyses ) made me wonder. What do really the Ctx stands for? what state is it representing ?
The code is not commenting on this , can any body answer me?
Thanks .
In iDempiere the context is a Properties object that is global to the whole application.
You can think about the context as a global set of variables that you can access from any point of the system.
The context variables can be viewed clicking on the iDempiere icon, then navigating to the Errors tab, and then clicking on the View button, you'll find there the variables after the line:
=== Context ===
Within the context you can find a lot of information:
Login variables: some of those starting with #, like #AD_Role_ID
Defaults: records that are marked as default, also starting with #, like #C_BP_Group_ID
Accounting related variables: those starting with $, like $C_Currency_ID
Global Preferences: starting with P like P|AutoCommit
Window Preferences: starting with P and a number, example P132|GL_Category_ID
And then, the context variables that you're interested in, the value of each field on the windows that are open:
Window fields: those starting with a number, like 1|DiscountSchema - this means the field DiscountSchema in the first window opened
Tab fields: those starting with two numbers, like 1|2|DatePromised - this means the field DatePromised in the third tab (the number 2, tabs are numbered from zero) of the first window opened (the number 1)
You can access those context variables using Env.getContext... methods, and you can also add and delete your own variables with methods Env.setContext...
The use and intent of Context in ADempiere is the same as described by Carlos except for the access. In the web you can access the context from the top right of the window as shown below.
Another example of how the context provides global state is in testing. Here is a snippet from a test setup class that initializes the context with the time and login information. The context can then be accessed by test classes performing integration tests with a database as if they were in actual use. The context here is limited to login information but it could be extended to include any other element of the context required for the tests.
#BeforeAll
public static void setUpBeforeClass() {
today = TimeUtil.getDay(System.currentTimeMillis());
ctx = Env.getCtx();
ctx.setProperty("#AD_Org_ID", Integer.toString(AD_ORG_ID));
ctx.setProperty("#AD_User_ID", Integer.toString(AD_USER_ID));
ctx.setProperty("#AD_Client_ID", Integer.toString(AD_CLIENT_ID));
ctx.setProperty("#Date", TimeUtil.getDay(System.currentTimeMillis()).toString());
ctx.setProperty("#AD_Language", "en");
Ini.setClient (IS_CLIENT);
Ini.loadProperties(false);
org.compiere.Adempiere.startup(IS_CLIENT);
trxName = Trx.createTrxName("TestRun_" + randomString(4));
trx = Trx.get(trxName, false);
try {
mainSavepoint = trx.setSavepoint("AllTests_" + randomString(4));
} catch (SQLException e) {
fail(e.getMessage());
}
}
#AfterAll
public static void tearDownAfterClass() {
try {
tryToRollback(mainSavepoint);
trx.close();
}
catch(SQLException e) {
fail("Unable to rollback. " + e.getMessage());
}
finally {
trx.close();
trx = null;
ctx = null;
}
}
I want to disable make a copy option when user do right click on documents in m-files, until no body cant copy documents to other class to use,
is there anybody to help me to solve it?
You can achieve this with M-Files User Interface Extensibility Framework.
The needed function is shellFrame.Commands.SetCommandState(9, CommandLocation_All, 3).
1st parameter is command ID (list of built-in command IDs, 9 is BuiltinCommand_MakeCopy)
2nd parameter defines the parts of the UI where you want to set the new command state
3rd parameter defines the new state (3 is CommandState_Hidden)
You will need to set up the UI extension with some configuration files but there is a sample that comes close to your use-case: Alter Context Menu Depending on SelectedObject. The code to hide the context menu option in main.js would be:
"use strict";
function OnNewShellUI(shellUI) {
shellUI.Events.Register(
Event_NewNormalShellFrame,
handleNewNormalShellFrame);
}
function handleNewNormalShellFrame(shellFrame) {
shellFrame.Events.Register(
Event_Started,
getShellFrameStartedHandler(shellFrame));
}
function getShellFrameStartedHandler(shellFrame) {
return function () {
shellFrame.Commands.SetCommandState(9, CommandLocation_All, 3);
};
}
I have a problem with selecting a property on a compartmentshape of a dsl. What I want to do is:
I have a DSL with one compartmentshape which has many properties in one compartment. Each of this properties has a textfield which is used for saving c# code. I compile this code and add the error tasks to the error list. I added an event handler for the navigate event of the error task. Inside this handler, i would like to select the property of the compartmentshape which is responsible for the error. I tried many things, but didn't succeeded. This is my current selection logic:
public void Select(Rule rule)
{
Library.Field ruleField = rule.Field as Library.Field;
var ruleFieldPresentation = PresentationViewsSubject.GetPresentation(ruleField as ModelElement).FirstOrDefault() as ShapeElement;
VSDiagramView activeDiagramView = Diagram.ActiveDiagramView as VSDiagramView;
if (activeDiagramView != null)
{
var docView = activeDiagramView.DocView;
activeDiagramView.Selection.Clear();
docView.CurrentDiagram.ActiveDiagramView.Selection.Set(new DiagramItem(ruleFieldPresentation));
}
}
The problem seems that an property of the compartmentshape doesn't have a presentationview, because I'm not able to get it.
I would be glad and very grateful if someone can helpe me with this problem.
Thank you
Regards Manuel
I wanted to open an error from the error list. There is a better solution than using the navigation event on an error. The better solution is to add a validation rule to the domain class and add the error with the context to the error list. Than the navigation to the property works out of the box.
context.LogError(errorDescription, "GAIN001RuleCompilationError", Field);
I'm developing my first app and I'm trying to make it multilanguage.
Using AppHub example and some other link I created my resource files, fixed binding strings on my components and set a settings page.
First problem I had was that menu items and appbar buttons couldn't use localization strings (project complained when launched) so I have:
TextBlocks and other components binded with localized strings
Appbar buttons and items localized manually with a procedure loading localized strings
Now that I have my settings page, one item user can change is language.
Well, correct CultureInfo is selected according to user selection and then I use
Thread.CurrentThread.CurrentUICulture = Settings.Language;
When I press back button and return to main page, appbar items are localized correctly, while everything else is not.
The only workaround (that I really don't like, it's just to understand) is this:
public MainPage()
{
Thread.CurrentThread.CurrentUICulture = Settings.Language;
InitializeComponent();
// Everything else I need here
}
so I have to set language before components are created to make it work.
What's wrong? Which is the correct way to make a page refresh after changing language using binded strings?
I did not put a lot of code because I used basically the one provided in the link, but if you need more info I will edit my question.
I finally found a solution to automatically update my application components reacting to language change.
A good tutorial can be found here; briefly you must find a way to notify your app that localized resource is changed.
public class LocalizedStrings : ViewModelBase
{
private static AppResources localizedresources = new AppResources();
public AppResources LocalizedResources
{
get { return localizedresources; }
}
public void UpdateLanguage()
{
localizedresources = new AppResources();
RaisePropertyChanged(() => LocalizedResources);
}
public static LocalizedStrings LocalizedStringsResource
{
get
{
return Application.Current.Resources["LocalizedStrings"]
as LocalizedStrings;
}
}
}
With this when user change language, you should simply run
LocalizedStrings.LocalizedStringsResource.UpdateLanguage();
and the job is done.
I am getting up to speed on Composite WPF, building a small demo app to work through the issues. My app has one region, and two modules, Module A and Module B. Each module contains a simple "Hello World" text block. Both modules are set up as load-on-demand, as per this MSDN How-To.
The shell has two buttons, "Load Module A" and "Load Module B". When a button is clicked, the corresponding module is loaded. So, lets say I click "Load Module A", then "Load Module B". Module A, then Module B load as expected. But if I click "Load Module A" again, nothing happens.
I'm stuck at this point. I think my problem is that I need to activate and deactivate the views in the modules, rather than using load-on-demand. But I have no idea how to do that, and I can't find any documentation or blogs that talk about it.
So, here's my question: How to I load/unload (or show/hide) views? If someone can point me to sample code, I'd really appreciate it. Thanks for your help.
I found my answer. Here is the approach: Load all the modules at startup, then activate and deactivate views as you need them. I am going to write this issue up as a CodeProject article, but here is an outline of how to do it:
(1) In the module Initialize() method, add the module, but don't activate it:
public void Initialize()
{
// Get main region
var mainRegion = m_RegionManager.Regions["MainRegion"];
// Load Module B
var newView = new ModuleBView();
mainRegion.Add(newView, "ModuleA.ModuleAView");
}
Note that the Add() method has two parameters. The second parameter is the name of the view, which we set to the value produced by the ToString() method of the view. We'll see why in the next step.
(2) When activating a view, we need to deactivate the previous view. But we may not know the name of the view, so we deactivate all active views:
public static void ClearRegion(IRegion region)
{
// Get existing view names
var oldViewNames = new List<string>();
foreach (var v in region.Views)
{
var s = v.ToString();
oldViewNames.Add(s);
}
// Remove existing views
foreach (var oldViewName in oldViewNames)
{
var oldView = region.GetView(oldViewName);
region.Deactivate(oldView);
}
}
Since we set the name of each view equal to its ToString() value, we can get the names easily without knowing anything about them in advance.
(3) Now we activate the new view. I do it in an MVVM ICommand.Execute() method:
public void Execute(object parameter)
{
// Get main region
var mainRegion = m_ViewModel.RegionManager.Regions["MainRegion"];
// Clear region
ModuleServices.ClearRegion(mainRegion);
// Activate Module A view
var moduleAView = mainRegion.GetView("ModuleA.ModuleAView");
mainRegion.Activate(moduleAView);
}
Hopefully, that will be enough to get you going. Like I said, I plan to do a more complete writeup, with demo code, for CodeProject.
David Veeneman
Foresight Systems