Custom TROIA Component'leriCustom TROIA Components
Custom business katmanı component'leri tanımlamak ve bu component'lerin instance'larını farklı dialog'larda veya başka component'lerde kullanmak mümkündür. Bu bölüm, "custom component"lerin nasıl tanımlandığını ve kullanıldığını göstermeyi amaçlar.Its possible to define custom business layer components and use instances of these components on different dialogs or other components. This sections aims to show how “custom components” are defined and used.
Dialog user interface'leri geliştirirken, programcılar button, textfield, label (ui control) gibi ui item'ları kullanır. Ama bazı durumlarda, programcıların farklı dialog'lardaki mevcut kodları kopyalayıp yapıştırmaktan kaçınmak için bir control setini farklı dialog'larda yeniden kullanması gerekebilir. Custom bir TROIA component'i, belirli bir action'ı gerçekleştirmek için bir veya daha fazla basit control içeren, yeniden kullanılabilir custom bir ui control'üdür. Custom component'ler, dialog veya class gibi bir TROIA development item türüdür. Custom TROIA component'i kısaca "component" olarak adlandırılır.While developing dialog user interfaces, programmers use ui items such as buttons, text fields, labels (ui controls). But in some cases, programmers may need to reuse a set of controls on different dialogs to avoid copying and pasting existing codes on different dialogs. A custom TROIA component is a reusable custom ui control which contains one or more simple controls to perform a specific action. Custom components are a type of TROIA development items such as dialogs or classes. Custom TROIA component is called as “component”, shorty.
Örneğin, bir uçuş rezervasyon application'ı için biri departure date, diğeri returning departure date için iki date chooser'a ihtiyacınız olabilir ve girilen date'lerin geçerli olup olmadığı veya sıranın doğru olup olmadığı gibi bir dizi validity kontrolü yapmanız gerekir. Gerekli tüm kodu bir dialog'a yazarsanız, bir hotel rezervasyon application'ı için benzer bir control setine ihtiyacınız olduğunda troia code'unu kontrol etmeniz gerekir. Component infrastructure'ını kullanarak date chooser'ınızı bir component olarak tanımlar ve farklı dialog'larda kullanırsınız.For instance, for a fligh reservation application you may need two date chooser one is for departure date and second one is returning departure date and you have to make a set of validity checks whether inserted dates are valid or correct order etc. If you write whole required code on a dialog, you have to controls troia code when you need a similar control set for an hotel reservation application. Using component infrastructure you define your date chooser as a component and use it on different dialogs.
Component'ler Nasıl Saklanır?How Components Stored?
Görüldüğü gibi, component'lerin control'leri, control event'leri ve method'ları vardır. Bu yüzden bir component, sahip olduğu item'lar açısından dialog'a benzer. Dialog'lara benzer şekilde, component data'sı zaten dialog'ları saklamak için kullanılan development table'larında saklanır. Bu table'lar SYSDIALOGS, SYSDLGTEXTS, SYSDLGCODES, SYSDLGFUNCTEX, SYSCONTROLS, SYSCTLTEXTS'tir. Bu table'ların rolleri hakkında daha fazla bilgi için lütfen "Dialog Basics/How Dialogs are Stored?" bölümüne bakınız.As it is obvious, components have controls, control events and methods. Therefore a component is similar to dialog from the aspect of items that they have. Similar to dialogs component data is stored on development tables which are already used for storing dialogs. This tables are SYSDIALOGS, SYSDLGTEXTS, SYSDLGCODES, SYSDLGFUNCTEX, SYSCONTROLS, SYSCTLTEXTS. For more information about the roles of this table, please see “Dailog Basics/How Dialogs are Stored?” section.
Component TanımlamaDefining Components
Diğer troia development item'larına benzer şekilde, component'ler de TROIA IDE kullanılarak tanımlanır. Yeni bir component oluşturmak için, menüde TROIA IDE-> New -> New Component'e tıklamalı ve new dialog form'una çok benzeyen new component form'unu doldurmalısınız.Similar to other troia development items, components are defined using TROIA IDE, too. To create a new component, you must click TROIA IDE-> New -> New Component on menu and fill the new component form which is very similar to new dialog form.
Bu formda bir hotline (change request) seçmeli ve geçerli bir component ismi girmelisiniz. Geçerli bir component ismi, dialog'lara benzer şekilde benzersizdir ve en az dört karakter uzunluğundadır.In this form you, must select a hotline (change request) and enter a valid component name. A valid component name is unique and at least four characters length similar to dialogs.
Inheriting ve cross reference tanımlama da component'ler için desteklenir ve dialog'larla aynı şekilde çalışır. Inheriting hakkında daha fazla bilgi için ilgili bölüme bakınız.Inheriting and defining cross references are also supported for components and works in same way with dialogs. Please see the related section to get more informatin about inheriting.
"OK" butonuna tıkladıktan sonra, IDE yeni bir component oluşturur ve design window'unu açar. Bu design window'da gereksinimlerinize göre component'inizi oluşturabilirsiniz. İşte üzerinde iki date field'ı olan örnek component'im.After you click “OK” button, IDE creates a new component and opens design window. In this design window you can create your component due to your requirements. Here is my sample component that has two date fields on it.
Component'leri KullanmaUsing Components
Bir dialog'da bir component kullanmak için, toolbox'tan bir "TROIA Component" (1) sürükleyip dialog'a (2) bırakmalısınız. Ve sürüklediğiniz control'ün "Component" feature'ına component ismini yazmalısınız (3). Her component instance'ının, diğer control'ler gibi benzersiz bir control ismi olmalıdır.To use a component on a dialog, you must just drag a “TROIA Component” (1) from toolbox and drop it on dialog (2). And write the component name to “Component” feature of your dragged control (3). Each component instance must have a unique control name such as other controls.
Dialog'u kaydedip çağırdıktan sonra, son görünüm aşağıdadır. Bu dialog'un C1 (1) ve C2 (2) adlı iki component instance'ı vardır.After saving and calling the dialog, the final view is below. This dialog has two component instances named C1 (1) and C2 (2).
Nested Component'lerNested Components
Component'leri başka component'lerin içinde kullanmak da mümkündür. Bu süreç, bir dialog'da component kullanmakla tamamen aynıdır.It is also possible to use components inside other components. This process is totally same with using a component on dialog.
Component Event'leriComponent Events
Component'lerin, bir component instance'ı oluşturulduğunda çağrılan INITIALIZE adlı önceden tanımlı bir event'i vardır. Bu method ile TROIA programcıları bir component'in initial state'ini ayarlayabilir. INITIALIZE method'unu implement etmek için design view'de component'e sağ tıklamalı (1) veya properties explorer'ın altındaki events explorer'da event'e çift tıklamalısınız (2).Components have a predefined event named INITIALIZE which is called when a component instance is created. With this method TROIA programmers are able to set initial state of a component. To implement INITIALIZE method you must right click to component on design view (1) or double click the evet on events explorer which is under the properties explorer (2).
Örneğin, initialize method'una aşağıdaki kodu yazarsanız. Component'ler güncel date'i DATEFROM olarak ve yarını DATETO olarak gösterir.For example if you write the code below to initialize method. Components shows current date as DATEFROM and tomorrow as DATETO.
DATEFROM = CURRENTTIMEMILLIS();
DATETO = ADDDAYS(DATEFROM, 1);Component'ler & ScopeComponents & Scope
Developer'lar bir component geliştirirken hangi dialog'larda kullanılacağını bilemez. Variable isimleri dialog'lardaki mevcut variable'larla çakışırsa ne olur? Veya bir dialog component'in variable'larından birini değiştirirse? Aslında bu sorular component'ler için geçerli değildir çünkü component'lerin kendi scope'u vardır, bu yüzden bir component'te tanımlanan bir variable, bir dialog component'iyle aynı isme sahip olsa bile aynı variable değildir. Bu yüzden çakışmalar mümkün değildir. Örneğin, component scope'undaki SYS_STATUS, global scope'taki SYS_STATUS ile aynı değildir, tamamen farklı variable'lardır.Developers are not able to know in which dialogs component will be used while developing a component. What if varaible names conflicts with existing variables on dialogs? or if a dialog changes one of component’s variable? Actually this questions are not valid for components because components have their own scope, so even a variable defined in compoent has same name with a dialog component they are not same variables. Therefore conflictions are not possible. For example, SYS_STATUS in component scope is not same with SYS_STATUS in global scope, they are totally different variables.
Component'te Tanımlanan Variable'lara ErişmeAccessing Variables Which Defined in Component
Component'lerin farklı bir scope'a sahip olmasının bir sonucu olarak, dialog kodlarından component'te tanımlanan variable'lara erişmek (okumak veya ayarlamak) mümkün değildir. Bunu yapmak için, component'in böyle method'ları varsa public method'larını çağırmalısınız. Getter/setter method'ları tanımlamak, component'i geliştiren programcının sorumluluğundadır. Component method'larını çağırma ilerleyen bölümlerde ele alınacaktır.As a result of component’s have a different scope, it is not possible to access (read or set) variables defined in component from dialog codes. To do this you must call component’s public methods, if component have such methods. Defining getter/setter methods is the responsibility of programmer who developes component. Calling component methods will be discussed in next sections.
Component'lerden Dialog ÇağırmaCalling Dialogs from Components
Bir component'ten bir dialog çağırmak da mümkündür. Component'lerden çağrılan dialog'lar component'in bir parçasıdır, bu yüzden dialog'da (kod veya control symbol'leriyle) tanımlanan tüm variable'lar component'in scope'unda bulunur.Also it is possible to call a dialog from component. Dialogs which is called from components are a part of the component, so all variables defined on dialog (by code or control symbols) are located in component’s scope.
Component Method'larını ÇağırmaCalling Component Methods
Component'lerin, component dışından çağrılabilen bazı public method'ları olabilir. Böyle bir method tanımlamak için, IDE'de sağ tık menüsünden "Add Method"u seçmeli ve method içeriğini doldurmalısınız.Components is able to have some public methods that can be called from outside the component. To define such a method, you must select “Add Method” from right click menu on IDE and fill method content.
Bir component'in method'unu çağırmak, bir class method'unu çağırmaktan farklı değildir. Method'u component'in instance ismi için çağırmalısınız. İşte DEMOCOMPONENT'in bir instance'ı olan C1'in SETVALUS() method'unu çağıran örnek dialog kodu.Calling a component’s method is not different from calling a class method. You must call the method for the component’s instance name. Here is sample dialog code that calls SETVALUS() method of C1 which is an instance of DEMOCOMPONENT.
C1.SETVALUES('01.01.2016 10:10:10', '01.02.2017 10:10:10');Bu kod C1'in context'inde çalışır ve yalnızca C1 instance'ının FROM ve TO date'lerini değiştirir. DEMOCOMPONENT'in diğer instance'ları bu çağrıdan etkilenmez.This code runs on C1’s context and changes only FROM and TO dates of C1 instance. Other instances of DEMOCOMPONENT are not affected from this call.
Component Action'larıComponent Actions
Bazı durumlarda, bir component'in davranışı kullanıldığı dialog'a göre değişebilir. Örneğin, kullanıcı FROM field'ına TO date'inden daha geç bir date girerse component'imiz kullanıcıyı uyarmalıdır. Ama warning mesajı dialog'a veya component instance'ına göre değişebilir. Bu durumlarda, component'ler her component instance'ı için doldurulması gereken bazı abstract method'lar içerebilir. Böyle bir action tanımlamak için, action isimleri IDE Properties Explorer'da ACTION field'ında tanımlanmalıdır. Birden fazla action için, ayırıcı olarak noktalı virgül kullanın.In some cases, behaviour of a component can be change due to dialog that it is used on. For example, if user enters a date which is later than TO date to FROM field our component must warn the user. But warning message can be change due to dialog or component instance. In this cases, components can contain some abstract methods that must be filled for each component instance. To define such an action, action names must be defined in ACTION field on IDE Properties Explorer. For multiple actions, use semicolumn as seperator.
Temel olarak, component action'ları button'ların Click veya textfield'ların LoseFocus'u gibi herhangi bir control event'ine benzerBasically, component actions are similar to any control event like buttons’ Click or textfields’ LoseFocus
Bu action'lar, component instance'ına IDE'de sağ tıklanarak, component'in her instance'ı için ve component'in kullanıldığı dialog'ların parçası olarak implement edilir. Bir action'ı tetiklemek için FIRECOMPONENTEVENT kullanılır. İşte temel syntax:This actions are implemented for each instance of component and part of dialogs that component is used, by right clicking on the component instance on IDE. To fire an action FIRECOMPONENTEVENT is used. Here is the basic syntax:
FIRECOMPONENTEVENT {eventname};Örneğin, component'imizde FROM date'inin TO date'inden daha erken olup olmadığını kontrol edebiliriz. Component'te bir CHECKVALIDITY() method'umuz olduğunu ve DATETO ve DATEFROM textfield'larının TextChanged event'lerinden çağrıldığını varsayalım. İşte component'imizin CHECKVALIDITY() method'unun kodu.For example, we can check whether FROM date is earlier than TO date in our component. Assume that we have a CHECKVALIDITY() method on component and it is called from TextChanged events of DATETO and DATEFROM textfields. Here is the code of CHECKVALIDITY() method of our component.
IF DATEFROM > DATETO THEN
FIRECOMPONENTEVENT 'INVALIDDATE';
ENDIF;