How to add additional attachments in the workflow? - workflow

In my document management process it is often necessary to provide some additional documents (e.g. list of comments, list of differences, some screenshot, etc).
These additional documents would be convenient to add in the Activiti forms. I would like to be able to add documents at the initiation stage of a business process and at the stage of the revise.
For this, I added an aspect with associations in the workflow-model.xml (relevant part):
...
<type name="mswf:activitiRevise">
...
<mandatory-aspects>
...
<aspect>mswf:attachments</aspect>
</mandatory-aspects>
</type>
...
<aspect name="mswf:attachments">
<associations>
<association name="mswf:package">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cm:content</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
</aspect>
...
etc
In share-config-custom.xml I have the following (relevant part):
...
<config evaluator="task-type" condition="bpm:startTask">
<forms>
<form id="workflow-details">
<field-visibility>
...
<show id="mswf:package" />
</field-visibility>
<appearance>
...
<set id="attachments" appearance="title" label-id="Additional docs" />
<field id="mswf:package" set="attachments" />
</appearance>
</form>
<form>
<field-visibility>
<show id="mswf:package" />
...
</field-visibility>
<appearance>
<set id="attachments" appearance="title" label-id="Additional docs" />
<field id="mswf:package" set="attachments" />
...
</appearance>
</form>
</forms>
</config>
...
etc
Now I have an additional field where I can choose the appropriate documents.
It works - I added some documents and can see them at all of the stages of the document management process.
The problem occurs when I try to change a set of initially selected files. For example, when I try to add a new one. If I add a new one (or remove) - changes are not saved and in the next task, I see the same documents that were selected at the beginning.
To get control of this behavior, I developed WebScript, in which I try to manage properties. I call the WebScript from Share in the getAddedItems() method:
/**
* Returns items that have been added to the current value
*
* #method getAddedItems
* #return {array}
*/
getAddedItems: function ObjectFinder_getAddedItems() {
var addedItems = [],
currentItems = Alfresco.util.arrayToObject(this.options.currentValue.split(","));
for (var item in this.selectedItems) {
if (this.selectedItems.hasOwnProperty(item)) {
if (!(item in currentItems)) {
addedItems.push(item);
}
}
}
...
// here the call to the WebScript
return addedItems;
},
Part of my Java-backed WebScript:
...
public class WorkflowAttachmentsManipulator extends DeclarativeWebScript {
private static final String WORKFLOW_MODEL_URI = "...";
private WorkflowService workflowService;
#Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
Map<String, Object> model = new HashMap<>();
String taskId = req.getParameter("taskId");
String addedItem = req.getParameter("addedItem");
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
Map<QName, Serializable> taskProperties = workflowTask.getProperties();
...
taskProperties.replace(
QName.createQName(WORKFLOW_MODEL_URI, "package"), oldValue, addedItem);
workflowService.updateTask(taskId, taskProperties, null, null);
...
I'm trying to replace the selected files with some arbitrary and the replace(...) method returns true. In alfrescotomcat-stdout.2017-09-06.log I also see that the property has been replaced:
Before calling the WebScript (two files in the package):
key: {WORKFLOW_MODEL_URI_HERE}package
value: [workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a,
workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769]
After calling the WebScript (one file in the package):
key: {WORKFLOW_MODEL_URI_HERE}package
value: workspace://SpacesStore/1a0b110f-1e09-4ca2-b367-fe25e4964a4e
After updating the form at the current task I see my new file.
But the value is not saved (lost) after revise / review and in the next task I see the same files. Let's say, the task ID for the current user was activiti$204587, then it became equals activiti$204647...
I added some debugging code to the BPMN diagram and found that the contents of mswf_package did not change after the calling the WebScript.
In 'Submit', main config:
for(var i = 0; i < mswf_package.size(); i++) {
logger.log(mswf_package.get(i).nodeRef);
}
Output:
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769
In 'Review Task', listeners of the create and complete events:
for(var i = 0; i < mswf_package.size(); i++) {
logger.log(mswf_package.get(i).nodeRef);
}
Output:
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769
How to add additional attachments in the workflow? Is it possible?

A set of strings with NodeRefs can be passed to the following WebScript, for example:
public class WorkflowAttachmentsManipulator extends DeclarativeWebScript {
private static final String WORKFLOW_MODEL_URI = "...";
private WorkflowService workflowService;
#Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
Map<String, Object> model = new HashMap<>();
String taskId = req.getParameter("taskId");
String addedItems = req.getParameter("addedItems");
String oldValue = "";
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
Map<QName, Serializable> taskProperties = workflowTask.getProperties();
Iterator taskIterator = taskProperties.entrySet().iterator();
while(taskIterator.hasNext()) {
Map.Entry taskPair = (Map.Entry)taskIterator.next();
Object key = taskPair.getKey();
if(key != null &&
key.toString().equalsIgnoreCase("{" + WORKFLOW_MODEL_URI + "}package")) {
if(taskPair.getValue() != null) {
oldValue = taskPair.getValue().toString();
if(!oldValue.equals("[]")) {
oldValue = oldValue.replaceAll("[\\[\\]]", "");
addedItems = "[" + oldValue + "," + addedItems + "]";
} else {
if(addedItems.indexOf(",") > 0) {
addedItems = "[" + addedItems + "]";
}
}
}
taskProperties.replace(
QName.createQName(WORKFLOW_MODEL_URI, "package"),
oldValue,
addedItems);
workflowService.updateTask(workflowTask.getId(),
taskProperties, null, null);
break;
}
}
...
}
public WorkflowService getWorkflowService() {
return workflowService;
}
public void setWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
}
This code overrides attachments for the certain task.
Additional files need to differentiate from those that are involved in the document management process. It can be done, for example, as follows:
/**
* Returns items that have been added to the current value
*
* #method getAddedItems
* #return {array}
*/
getAddedItems: function ObjectFinder_getAddedItems() {
var addedItems = [],
currentItems = Alfresco.util.arrayToObject(this.options.currentValue.split(","));
var attachments = [];
for (var item in this.selectedItems) {
if (this.selectedItems.hasOwnProperty(item)) {
if (!(item in currentItems)) {
// modified for differentiation
if (this.options.displayMode == "items") {
attachments.push(item);
} else {
addedItems.push(item);
}
}
}
}
...
// call to the WebScript with attachments
// modified for merge
return addedItems.concat(attachments);
},
For saving the overridden attachments in the process variable it is necessary to define the listener of the complete event.
Moreover, it is possible to "pass" files by the chain from task to task (with changes) by using this technique:
Listener of the complete event:
public class TaskCompleteListener implements TaskListener {
#Override
public void notify(DelegateTask delegateTask) {
DelegateExecution execution = delegateTask.getExecution();
execution.setVariable("mswf_package", delegateTask.getVariable("mswf_package"));
}
}
Listener of the create event:
public class TaskCreateListener implements TaskListener {
#Override
public void notify(DelegateTask delegateTask) {
DelegateExecution execution = delegateTask.getExecution();
delegateTask.setVariable("mswf_package", execution.getVariable("mswf_package"));
}
}
This solved my issue.

Related

From an select item in the list, create another listbox ZK

I had a headache with this. I want to choose a book from the 1st list and with that book create a second list to be able to show the details of the book (title, number of pages)
Here is the code:
public class Book {
private int numBook;
private String nameBook;
private String author;
public Book(int numBook, String nameBook, String author) {
super();
this.numBook = numBook;
this.nameBook = nameBook;
this.author = author;
}
public int getNumBook() {
return numBook;
}
public void setNumBook(int numBook) {
this.numBook = numBook;
}
public String getNameBook() {
return nameBook;
}
public void setNameBook(String nameBook) {
this.nameBook = nameBook;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
Class BookData: Load the info in array
public class BookData {
private List<Book> books = new ArrayList<Book>();
public BookData() {
loadBooks();
}
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
public void loadBooks() {
Book b;
for(int i = 0; i<4;i++){
b = new Book(i+1, "Libro "+i+1, "Author "+i+1);
books.add(b);
}
}
}
Class BookViewModel: ViewModel of Listbox
public class BookViewModel {
private static Book selectedBook;
private List<Book> booksData = new ArrayList<Book>(new BookData().getBooks()); // Armo los libros
public List<Book> getBooksData() {
return booksData;
}
public void setBooksData(List<Book> booksData) {
this.booksData = booksData;
}
//Getters and Setter the SelectedCar
#NotifyChange("selectedBook")
public Book getSelectedBook() {
if(selectedBook!=null) {
//setSelectedBook(selectedBook);
new DetailData(selectedBook);
//new ArrayList<>(new DetailData().getDetailsFilterByBook());
//Then here pass the Book Selected
}
return selectedBook;
}
public void setSelectedBook(Book selectedBook) {
this.selectedBook = selectedBook;
}
}
Class Detail: Detail Model of the choose Book
public class Detail {
private int idBook;
private String title;
private int numPages;
public Detail(int idBook, String title, int numPages) {
this.idBook = idBook;
this.title = title;
this.numPages = numPages;
}
public int getIdBook() {
return idBook;
}
public void setIdBook(int idBook) {
this.idBook = idBook;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getNumPages() {
return numPages;
}
public void setNumPages(int numPages) {
this.numPages = numPages;
}
#Override
public String toString() {
return "Detail [idBook=" + idBook + ", title=" + title + ", numPages=" + numPages + "]";
}
}
Class DetailData: Load the data in array
//Clase que se ecarga de manejar la data
public class DetailData {
private List<Detail> details = loadAllDetails();
private List<Detail> detailsFilterByBook;
private static Book bookSelected;
/*public DetailData(){
//Previously all the data is loaded
System.out.println(bookSelected);
detailsFilterByBook = new ArrayList<>();
filterDetailsByBook();
}*/
public void setBookSelected(Book bookSelected){
this.bookSelected = bookSelected;
}
public DetailData(){
this(bookSelected);
}
public DetailData(Book b){
bookSelected = b;
System.out.println(bookSelected);
detailsFilterByBook = new ArrayList<>();
filterDetailsByBook();
}
public List<Detail> loadAllDetails(){
List tmp = new ArrayList<Detail>();
//Libro 1
Detail d1b1 = new Detail(1, "Preview", 15);
Detail d2b1 = new Detail(1, "Inicio", 10);
Detail d3b1 = new Detail(1, "Zk Bind", 50);
//Libro 2
Detail d1b2 = new Detail(2, "Introduccion", 15);
Detail d2b2 = new Detail(2, "JAVA", 100);
Detail d3b2 = new Detail(2, "CSS", 25);
//Libro 3
Detail d1b3 = new Detail(3, "HTML", 35);
Detail d2b3 = new Detail(3, "Javascript", 40);
Detail d3b3 = new Detail(3, "Ajax", 25);
//Libro 4
Detail d1b4 = new Detail(4, "Android", 100);
Detail d2b4 = new Detail(4, "IOS", 100);
tmp.add(d1b1);
tmp.add(d2b1);
tmp.add(d3b1);
tmp.add(d1b2);
tmp.add(d2b2);
tmp.add(d3b2);
tmp.add(d1b3);
tmp.add(d2b3);
tmp.add(d3b3);
tmp.add(d1b4);
tmp.add(d2b4);
return tmp;
}
private void filterDetailsByBook() {
for(Detail d:details){
if(d.getIdBook() == bookSelected.getNumBook())
detailsFilterByBook.add(d);
}
print();
}
public void print(){
System.out.println("Imprimiendo detalles del libro escogido");
for(Detail d: detailsFilterByBook){
System.out.println(d);
}
}
public List<Detail> getDetails() {
return details;
}
public void setDetails(List<Detail> details) {
this.details = details;
}
public List<Detail> getDetailsFilterByBook() {
return detailsFilterByBook;
}
public void setDetailsFilterByBook(List<Detail> detailsFilterByBook) {
this.detailsFilterByBook = detailsFilterByBook;
}
}
Class: DetailViewModel:ViewModel of the second ListBox
public class DetailViewModel {
private List<Detail> detailsData = new ArrayList<>();
#NotifyChange("detailsData")
public void refreshList(){
System.out.println("REFRESH");
detailsData = new ArrayList<>(new DetailData().getDetailsFilterByBook());
}
public List<Detail> getDetailsData() {
return detailsData;
}
#NotifyChange("detailsData")
public void setDetailsData(List<Detail> detailsData) {
this.detailsData = detailsData;
}
}
Here is the zul file
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer" viewmodel="#id('vm') #init('book.BookViewModel')">
<listbox model="#bind(vm.booksData)" selecteditem="#bind(vm.selectedBook)" emptymessage="No car found in the result">
<listhead>
<listheader label="Num Libro"/>
<listheader label="Libro"/>
<listheader label="Autor"/>
</listhead>
<template name="model" var="book">
<listitem>
<listcell label="#bind(book.numBook)"/>
<listcell label="#bind(book.nameBook)"/>
<listcell label="#bind(book.author)"/>
</listitem>
</template>
</listbox>
<separator height="100px"/>
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('detail.DetailViewModel')">
<listbox model="#bind(vm.detailsData)" emptyMessage="No existen datos que presentar">
<listhead>
<listheader label="Num Capitulos"/>
<listheader label="Titulo del Cap"/>
</listhead>
<template name="model" var="detail">
<listitem>
<listcell label="#bind(detail.idBook)"/>
<listcell label="#bind(detail.title)"/>
<listcell label="#bind(detail.numPages)"/>
</listitem>
</template>
</listbox>
</window>
</window>
I try in the second listbox (At begin have to be empty), show the details of the book everytime when a book in the 1st listbox is selected. I get the correct info. When I choose a book, I get the correct details of that book, but my second listbox does'nt show anything. I will apreciate all the help. PD: Sorry for the english
Oke, there are more points to say on this code then you imagine.
Never use static for a user/session variable.
In your VM you have the following code :
private static Book selectedBook;
Imagine that I select Book 1 and you select 2 seconds later Book 2.
Because it's static, I'm also having Book 2 selected, while mine view isn't aware of it.
This means the GUI and server side are out of sync => never a good thing.
If you could be able to sync the view with the selected item, this means that you select book 2 for me and I'll be searching the number of the Ghost Busters.
With ZK, always use ListModel interface to give collections to GUI.
While returning List<Book> works pretty good, you need to understand the consequences of this action.
A List or Grid expect an implementation of ListModel and if you don't give it, there will be one created every time you notify the list of a change.
While this is a nice to have feature it also removes the intelligence of a listmodel and the GUI rendering will be a lot more.
An example is always more clear :
We have a Collection of 9 items and we will append 1 to it.
Adding 1 Object to the List and notifying it implies that all the content rendered of the Listbox will be removed and then adding all the content again to the Listbox.
This means that we are removing and adding 9 lines who aren't changed.
Adding 1 Object to a ListModel, even without notifying the ListModel of a change will result in an action where there is only 1 item appended to the Listbox. This is the intelligence of a ListModel => adding and removing items will be persisted to the GUI without overhead.
So your code should be looking like this :
private Book selectedBook;
private final ListModelList<Book> booksData = new ListModelList<Book>(new BookData().getBooks()); // Armo los libros
Why not working to the interface and why final?
So I just told you about the interface ListModel and yet, I'm setting an implementation of ListModel as code, even while we learn to work against interfaces.
The simple reason is that ListModel doesn't have methods for appending and removing items while the implementation do have it.
So I make a decision to work against that object in stead of casting it when I need the methods.
Remember, the global getter for the booksData can look like this :
public ListModel<Book> getBooksData() {
return booksData;
}
So here we hide the implementation of ListModelList to the outside.
The reason for final is that you will forcing yourself or other people who are going through the code to use the clear() method in stead of making a new ListModelList.
It's just not needed to create a new instance of it.
Using 2 viewmodel's
Your making yourself difficult of using 2 VM's.
But while it's sometimes a good idea to do this I'll be helping you to get your problem solved.
Your first problem is one of a naming kind.
Viewmodel 1 => called vm in the zul.
Viewmodel 2 => called vm in the zul.
You see it coming? who will listen when I cry to vm?
let's call the viewmodel of the details detailVM
viewModel="#id('detailVM') #init('detail.DetailViewModel')"
The second problem is that your detail viewmodel doesn't have any clue of the first listbox.
What do I want to say is that your second viewmodel should be holding the correct info of the selected item of the first listbox.
Zul code should be looking like this :
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer" viewmodel="#id('vm') #init('book.BookViewModel')">
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('detailVM') #init('detail.DetailViewModel')">
<listbox model="#init(vm.booksData)" selecteditem="#bind(detailVM.selectedBook)" emptymessage="No book found in the result">
<listhead>
<listheader label="Num Libro"/>
<listheader label="Libro"/>
<listheader label="Autor"/>
</listhead>
<template name="model" var="book">
<listitem>
<listcell label="#load(book.numBook)"/>
<listcell label="#load(book.nameBook)"/>
<listcell label="#load(book.author)"/>
</listitem>
</template>
</listbox>
<separator height="100px"/>
<listbox model="#init(detailVM.detailsData)" emptyMessage="No existen datos que presentar">
<listhead>
<listheader label="Num Capitulos"/>
<listheader label="Titulo del Cap"/>
</listhead>
<template name="model" var="detail">
<listitem>
<listcell label="#load(detail.idBook)"/>
<listcell label="#load(detail.title)"/>
<listcell label="#load(detail.numPages)"/>
</listitem>
</template>
</listbox>
</div>
</window>
So I set you up with the correct zul, and now it's up to you to modify the viewmodels.
Remember that I set selectedBook in detailVM so now it's not needed in the first viewmodel.
I don't write everything for you, otherwise you wouldn't learn from it.
Some small things left to say.
You see I change the listbox model to #init and not #bind.
A model is always read only, so please NEVER NEVER NEVER use #bind.
#load is the highest annotation you could use, and this is only the case when you will create a new instance for the ListModel, witch is hardly needed.
Labels, are also not updatable in your GUI.
Again #bind is over the top, #load should be used in normal situations (when the value can change, so most commonly) or #init when the value will never change, but if you use #load I'll be happy already.
Hope this could set you to the right direction.
If you have any other question, just comment below.

The type 'StackedColumnSeries' does not support direct content [duplicate]

I am trying to use WinRTXamlToolkit.Controls.DataVisualization.UWP
trying to draw any of the stacked charts like this:
But only this comes out:
Please help me, I have to use stacked series but the framework doesn't act as it should be..
Since I don't know how you define the code behind, I just provide the sample code as follows which can create a StackedLineSeries chart successfully.
XAML Code
<Page
x:Class="CStackLineChat.MainPage"
...
xmlns:charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="50" >
<charting:Chart x:Name="MyChart" Title="Stacked column Chart">
<charting:StackedLineSeries>
<charting:StackedLineSeries.SeriesDefinitions>
<charting:SeriesDefinition
DependentValuePath="Amount"
IndependentValuePath="Name"
IsTapEnabled="True"
Title="Doodad" />
<charting:SeriesDefinition
Title="Stan2"
DependentValuePath="Amount"
IndependentValuePath="Name"/>
</charting:StackedLineSeries.SeriesDefinitions>
</charting:StackedLineSeries>
</charting:Chart>
</Grid>
</Page>
Code behind
public sealed partial class MainPage : Page
{
private Random _random = new Random();
List<NameValueItem> Records = new List<NameValueItem>();
List<NameValueItem> Records2 = new List<NameValueItem>();
public MainPage()
{
this.InitializeComponent();
for (int i = 0; i < 5; i++)
{
Records.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) });
Records2.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) });
}
this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[0].ItemsSource = Records);
this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[1].ItemsSource = Records2);
}
private void RunIfSelected(UIElement element, Action action)
{
action.Invoke();
}
}
public class NameValueItem
{
public string Name { get; set; }
public int Amount { get; set; }
}
And the result
Additionally, by testing on my side, it seems like DependentValuePath and IndependentValuePath properties can not directly binding in your scenario. The best way to use this package is to follow the official sample. Here is the chart sample.

CodeFluent BOM Producer select namespace

I would like to know if there is a way to select namespaces generated by one BOM producer. I would like to chose the target project for every namespace one by one in my model.
The Business Object Model (BOM) Producer does not allow you to select namespaces to generate. However you can create a CodeDom SubProducer which "remove" generated class before they are written to the disk. Here are some examples about sub-producers:
http://www.softfluent.com/documentation/webframe.html?CustomSubProducer_Topic.html
http://blog.codefluententities.com/2013/05/16/creating-a-custom-sub-producer-to-only-generate-resources/
The following subproducer allows to select namespaces to produce:
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Xml;
using CodeFluent.Model;
using CodeFluent.Model.Common.Design;
using CodeFluent.Model.Design;
using CodeFluent.Producers.CodeDom;
using CodeFluent.Runtime.Utilities;
namespace SelectNamespacesSubProducer
{
[Category("Business Layer Producers")]
[DisplayName("SubProducer Select Namespaces")]
[Producer(Constants.SubNamespaceUri, Constants.SubProducerNamespacePrefix)]
public class SelectNamespacesSubProducer : ICodeDomSubProducer
{
private CodeDomBaseProducer _baseProducer;
private CodeFluent.Producers.CodeDom.SubProducer _subProducer;
[Description("Determines if sub producer is enabled.")]
[Category("Configuration")]
[DefaultValue(true)]
[DisplayName("Is Enabled")]
[ModelLevel(ModelLevel.Normal)]
public virtual bool Enabled
{
get
{
return XmlUtilities.GetAttribute(Element, "enabled", true);
}
set
{
XmlUtilities.SetAttribute(Element, "enabled", value.ToString().ToLowerInvariant());
}
}
[Description("Determines the list of namespaces to produce.")]
[Category("Configuration")]
[DefaultValue(null)]
[DisplayName("Namespaces")]
[ModelLevel(ModelLevel.Normal)]
public virtual string Namespaces
{
get
{
return XmlUtilities.GetAttribute(Element, "namespaces", (string)null);
}
set
{
XmlUtilities.SetAttribute(Element, "namespaces", value);
}
}
public virtual void Initialize(CodeDomBaseProducer baseProducer, CodeFluent.Producers.CodeDom.SubProducer subProducer, IDictionary context)
{
_baseProducer = baseProducer;
_subProducer = subProducer;
baseProducer.CodeDomProduction += OnCodeDomProduction;
}
public virtual void Produce(IDictionary context, CodeCompileUnit unit)
{
}
public virtual void Terminate(IDictionary context)
{
}
private void OnCodeDomProduction(object sender, CodeDomProductionEventArgs e)
{
if (!Enabled)
return;
if (Namespaces == null)
return;
List<string> namespaces = ConvertUtilities.SplitToList<string>(Namespaces, ',', ';', '|');
switch (e.EventType)
{
case CodeDomProductionEventType.EntityCreating:
case CodeDomProductionEventType.SetCreating:
case CodeDomProductionEventType.EnumerationCreating:
var baseType = (BaseType)e.Argument;
if (!namespaces.Contains(baseType.Namespace))
{
e.Cancel = true;
FakeProduceUnit(baseType);
}
break;
}
}
private void FakeProduceUnit(BaseType baseType)
{
if (baseType == null)
throw new ArgumentNullException("baseType");
if (!_baseProducer.MustProduce(baseType, CodeFluent.Producers.CodeDom.Constants.ModelProducerNamespaceUri))
return;
Set set = baseType as Set;
if (set != null)
{
if (!_baseProducer.MustProduce(set.ItemEntity, CodeFluent.Producers.CodeDom.Constants.ModelProducerNamespaceUri))
return;
}
// determine the final target path where the file should have gone, and pretend it's been generated
string path = ((CodeDomProducer)_baseProducer).GetTargetPath(baseType);
path = _baseProducer.GetProductionTargetPath(baseType, path, false, false);
if (File.Exists(path))
{
_baseProducer.AddToGeneratedFiles(path);
}
}
public XmlElement Element
{
get
{
if (_subProducer == null)
throw new CodeFluentCodeDomProducerException(GetType().FullName);
return _subProducer.Element;
}
set
{
}
}
}
}
You can use it this way:
<cf:producer name="Business Object Model (BOM)" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
<cf:configuration compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\Sample" cfx:targetProject="..\Sample\Sample.csproj" cfx:targetProjectLayout="Update">
<subProducer typeName="SelectNamespacesSubProducer.SelectNamespacesSubProducer, SelectNamespacesSubProducer"
namespaces="Sample.NS1, Sample.NS2" />
</cf:configuration>
</cf:producer>
<cf:entity name="Customer" namespace="Sample.NS1">
<cf:property name="Id" key="true" />
</cf:entity>
<cf:entity name="Order" namespace="Sample.NS2">
<cf:property name="Id" key="true" />
</cf:entity>

GWT DataGrid setEmptyTableWidget, no results, and no horizontal scollbars when more columns than current window will display

I'm using a DataGrid in one of my layouts. I have successfully specified some static text to display when there are no results using setEmptyTableWidget(Widget). Usually, I pass something like new HTML("No results").
But... when I have more columns than I can fit within the view port (i.e., current display width of browser window), I do not see all column headers, nor can I scroll to (the right to) view them.
I have a layout that supports scrolling when there IS data! But the horizontal scrollbar DOES NOT appear when there is no data. I cannot see my way out of this problem.
Any hints or suggestions are welcomed.
Here's my layout... (you will see where I call setEmptyTableWidget in PagingDataTableDatGrid#initGrid(DataGridConfiguration)'s method implementation below).
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:gwt="urn:import:com.google.gwt.user.client.ui"
xmlns:com="urn:import:org.spp.im.mui.gwt.client.module.common.widget.grid">
<ui:with field="res" type="org.spp.im.mui.gwt.client.resources.UiResources" />
<ui:with field="msg" type="org.spp.im.mui.gwt.shared.i18n.UiMessages" />
<!-- Layout -->
<gwt:DockLayoutPanel width="100%" height="100%" styleName="{res.style.container}" unit="PX">
<gwt:north size="25">
<gwt:HorizontalPanel width="100%">
<!-- Buttons -->
<gwt:cell horizontalAlignment="ALIGN_RIGHT">
<com:GridButtonBar ui:field="bar" />
</gwt:cell>
</gwt:HorizontalPanel>
</gwt:north>
<gwt:center>
<!-- Grid -->
<com:ReadOnlyGrid ui:field="grid" width="100%" />
</gwt:center>
<gwt:south size="25">
<gwt:HorizontalPanel width="100%">
<!-- Pagination controls -->
<gwt:cell horizontalAlignment="ALIGN_LEFT">
<com:CustomPager ui:field="pager" width="225px" />
</gwt:cell>
</gwt:HorizontalPanel>
</gwt:south>
</gwt:DockLayoutPanel>
</ui:UiBinder>
ReadOnlyGrid is a custom implementation...
public class ReadOnlyGrid extends PagingDataTableDataGrid<DataRow> {
private Set<Column<DataRow, ?>> columns = new HashSet<Column<DataRow, ?>>();
// preferred constructor in most cases
public ReadOnlyGrid() {
super();
}
public ReadOnlyGrid(final DataGridConfiguration config) {
super(config);
}
#Override
protected Set<Column<DataRow, ?>> allColumns() {
return columns;
}
#Override
// first column always has default ascending sort order
public void initTableColumns(final DataGrid<DataRow> dataGrid, final DataTable table,
final ListHandler<DataRow> sortHandler) {
Column<DataRow, String> column;
final int totalColumns = table.getColumnCount();
String columnName = null;
ColumnHints columnHints = null;
for (int col = 0; col < totalColumns; col++) {
final int c = col;
columnName = table.getColumnName(c);
columnHints = table.getColumnHints(columnName);
if (columnHints.isVisible()) {
column = new Column<DataRow, String>(new DataTableCell()) {
#Override
public String getValue(final DataRow row) {
String result = "";
if (row != null) {
result = row.get(c);
}
return result;
}
};
column.setSortable(true);
sortHandler.setComparator(column, new Comparator<DataRow>() {
#Override
public int compare(final DataRow r1, final DataRow r2) {
final String one = r1.get(c);
final String two = r2.get(c);
if (one == null ^ two == null) {
return one == null ? -1 : 1;
}
if (one == null && two == null) {
return 0;
}
return one.compareToIgnoreCase(two);
}
});
final String header = columnHints.getColumnHeader() == null ? columnName : columnHints.getColumnHeader();
// create the column header
// header should have the same alignment as the column data
dataGrid.addColumn(column, createHeader(header, columnHints.getColumnAlignment()));
// keep track of columns added
allColumns().add(column);
// Set the column width
dataGrid.setColumnWidth(column, columnHints.getColumnWidth(), Unit.PX);
// Set the column alignment
if (columnHints.getColumnAlignment() != null) {
column.setHorizontalAlignment(columnHints.getColumnAlignment());
}
else {
column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);//default
}
if (c == 0) {
dataGrid.getColumnSortList().push(column);
}
}
}
}
#Override
protected void initTableRows(final DataTable table) {
setDataList(table.allRows());
}
private SafeHtml createHeader(final String columnHeaderHtml, HasHorizontalAlignment.HorizontalAlignmentConstant columnHeaderAlignment) {
columnHeaderAlignment = columnHeaderAlignment == null ? HasHorizontalAlignment.ALIGN_RIGHT : columnHeaderAlignment;
final String ch = replaceCrWithBr(columnHeaderHtml);
final SafeHtmlBuilder sb = new SafeHtmlBuilder();
sb.appendHtmlConstant("<div align=\"" + columnHeaderAlignment.getTextAlignString() + "\">")
.appendHtmlConstant(ch).appendHtmlConstant("</div>");
final SafeHtml header = sb.toSafeHtml();
return header;
}
private String replaceCrWithBr(final String value) {
String result = value;
if (value.contains(App.INSTANCE.carriage_return())) {
result = value.replace(App.INSTANCE.carriage_return(), App.INSTANCE.separator());
}
return result;
}
}
And PagingDataTableDataGrid...
public abstract class PagingDataTableDataGrid<T extends DataRow> extends Composite {
private DataGrid<T> dataGrid;
private ListDataProvider<T> dataProvider;
private ResizeLayoutPanel wrapper;
// default, use in UiBinder template when you just want to #UiField inject a subclass
public PagingDataTableDataGrid() {
this(new DefaultDataGridConfiguration());
}
// alternate, use in UiBinder template when you want to create an instance
// yourself, user to inject w/ #UiField(provided=true)
public PagingDataTableDataGrid(final DataGridConfiguration config) {
wrapper = new ResizeLayoutPanel();
wrapper.setWidth("100%");
wrapper.setStyleName(UiResources.INSTANCE.style().gridWrapper());
initWidget(wrapper);
initGrid(config);
}
private void initGrid(final DataGridConfiguration config) {
dataGrid = new DataGrid<T>(config.getPageSize(), config.getResources());
final HTML noResults = new HTML(UiMessages.INSTANCE.no_results());
dataGrid.setEmptyTableWidget(noResults);
wrapper.clear();
wrapper.add(dataGrid);
}
public void setInput(final DataTable table) {
resetTableColumns();
dataProvider = new ListDataProvider<T>();
dataProvider.setList(new ArrayList<T>());
final ListHandler<T> sortHandler = new ListHandler<T>(dataProvider.getList());
dataGrid.addColumnSortHandler(sortHandler);
initTableColumns(dataGrid, table, sortHandler);
initTableRows(table);
dataProvider.addDataDisplay(dataGrid);
// trigger sort client-side
ColumnSortEvent.fire(dataGrid, dataGrid.getColumnSortList());
GridUtil.setStyles(this.dataGrid);
}
protected abstract Set<Column<T, ?>> allColumns();
// see
// http://stackoverflow.com/questions/3772480/remove-all-columns-from-a-celltable
// concrete classes are forced to maintain a handle on all columns added
private void resetTableColumns() {
for (final Column<T, ?> column : allColumns()) {
dataGrid.removeColumn(column);
}
allColumns().clear();
}
/**
* Add columns to this grid
*
* #param dataGrid
* a GWT DataGrid implementation
* #param table
* the model data
* #param sortHandler
* a GWT ListHandler implementation
*/
protected abstract void initTableColumns(DataGrid<T> dataGrid, DataTable table, ListHandler<T> sortHandler);
/**
* Add rows to this grid
* #param table the model data
*/
protected abstract void initTableRows(DataTable table);
protected void setDataList(final List<T> dataList) {
final List<T> list = dataProvider.getList();
list.addAll(dataList);
dataProvider.refresh();
}
public DataGrid<T> getDataGrid() {
return dataGrid;
}
}
So, as a "hack" I managed to get the behavior I wanted by using an insanely large pixel value for the width of the Widget.
E.g.,
Label noResults = new Label("No results");
noResults.setWidth("20000px");
This has the effect of pushing the text of the label all the way to the left, instead of it being centered underneath the column headers. But I can live w/ that, b/c the column headers are then scrollable.
There is nothing wrong with your code. It is as designed by the gwt. Why should a scroll appear if there is no data. Even I had similar doubt when working with datagrid but seriously it doesn't make sense to provide scroll when there is no data.

ZK Reordering With Listbox Without Drag And Drop Event

As i am trying This example well define by Nabil Abdel-Hafeez
It is working fine with some small issue which i already mentioned in tracker as issue. But i will want to Open a DualBox modal window in which one listbox contain all header name and other listbox will contain which header we will want to show for a listbox(I did this with getitemrendered ).I will want to use same ZUL Code without getitemrendered method.But user can hide the header which he/she do not want to see for a listbox. Anyone did this type of things?
Here
The green image with + Sign showing same thing which i will want to implement.
As I was trying the Nabil Abdel-Hafeez but my issue is that i will provide duallistbox where user can select which header he/she will want to see in listbox, user can select header by clicking on button ,user can add one header or all header from duallistbox and when user click on the Reorder button of duallistbox then it will reorder .In Nabil demo he is doing something like this..
for (Listitem item : lHead.getListbox().getItems()) {
item.insertBefore(item.getChildren().get(from), item.getChildren().get(to));
}
But if user selecting multiple how we will track which will come first which second and so on..
You can try combine MVVM with forEach so you can construct String array to display, this works since 6.0.2
e.g.,
zul
<zk>
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('test.TestVM')">
<listbox model="#load(vm.model)">
<listhead>
<listheader forEach="${vm.headers}" label="${each}" />
</listhead>
<template name="model" var="cells">
<listitem>
<listcell forEach="${cells}" label="${each}" />
</listitem>
</template>
</listbox>
<button label="original seq" onClick="#command('originalSeq')" />
<button label="reverse" onClick="#command('reverse')" />
</div>
</zk>
VM
package test;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import java.util.*;
public class TestVM {
private int[] _original = {1, 2, 3};
private int[] _reverse = {3, 2, 1};
private int[] _seq = _original;
private List _rawData;
public String[] getHeaders () {
String[] headers = new String[_seq.length];
for (int i = 0; i < _seq.length; i++) {
int idx = _seq[i];
headers[i] = (idx == 1? "First Name" :
idx == 2? "Last Name" :
idx == 3? "Age" : "");
}
return headers;
}
public ListModel getModel () {
if (_rawData == null) {
getRawData();
}
List modelData = new ArrayList();
for (int i = 0; i < _rawData.size(); i++) {
Person data = (Person)_rawData.get(i);
String[] cells = new String[_seq.length];
for (int j = 0; j < _seq.length; j++) {
cells[j] = data.getValue(_seq[j]);
}
modelData.add(cells);
}
return new ListModelList(modelData);
}
public void getRawData () {
_rawData = new ArrayList();
_rawData.add(new Person("First Name 01", "Last Name 01", 21));
_rawData.add(new Person("First Name 02", "Last Name 02", 22));
_rawData.add(new Person("First Name 03", "Last Name 03", 23));
}
#Command
#NotifyChange("model")
public void originalSeq () {
_seq = _original;
}
#Command
#NotifyChange("model")
public void reverse () {
_seq = _reverse;
}
class Person {
private String _firstName;
private String _lastName;
private int _age;
public Person (String firstName, String lastName, int age) {
_firstName = firstName;
_lastName = lastName;
_age = age;
}
public String getFirstName () {
return _firstName;
}
public String getLastName () {
return _lastName;
}
public int getAge () {
return _age;
}
public String getValue (int i) {
return i == 1? getFirstName() :
i == 2? getLastName() :
i == 3? getAge() + "" : "";
}
}
}
Regarding forEach, please refer to ZK Iterative Evaluation
Edit
Fully binded sample at ZK fiddle
Listbox Reorder Cells