This is a query I wrote:
public List<PrRevamps> fetchRevampHistory(String refNo) {
List<PrRevamps> list = dsl.select(
DSL.concat(
Tables.PR_REVAMPS.PR_REVAMP_CODE,DSL.val("-"),
Tables.PR_REVAMP_CODES.PR_DESCRIPTION
).as("DESCRIPTION"),
Tables.PR_REVAMPS.PR_REVAMP_DATE,
Tables.PR_REVAMPS.PR_KEY)
.from(Tables.PR_REVAMP_CODES,Tables.PR_REVAMPS)
.where(Tables.PR_REVAMPS.PR_REVAMP_CODE.equal(Tables.PR_REVAMP_CODES.PR_CODE))
.and(Tables.PR_REVAMPS.PR_PROP_REF_NO.equal(refNo))
.fetchInto(PrRevamps.class);
return list;
}
and I need to display revampCode and description in one row in vaadin grid.
i.e "A-Marshall"
This is the grid code below:
private void populateRevampGrid() {
Object ref = serv.getAttribute("ref");
String propRef = "";
if(ref != null) {
propRef = (String)ref;
List<PrRevamps> list = getService().fetchRevampHistory(propRef);
if(!list.isEmpty()) {
revampGrid.setContainerDataSource(new BeanItemContainer<>(list));
//revampGrid.addColumn("prRevampCode").setHeaderCaption("REVAMP DESCRIPTION");
revampGrid.removeColumn("prKey");
revampGrid.removeColumn("prLeaseType");
revampGrid.removeColumn("prPropRefNo");
revampGrid.getColumn("prRevampDate").setHeaderCaption("REVAMP DATE");
revampGrid.getColumn("prRevampCode").setHeaderCaption("REVAMP TYPE");
} else {
clearfields();
Notification.show("list is empty",Type.ERROR_MESSAGE.WARNING_MESSAGE);
}
}
}
As I understand, you have the description field, that has the desired value.
If not, you can add properties, generated from an object on the fly. But for this, you will need to use Container.
The full description can be found on Vaadin documentation https://vaadin.com/docs/v7/framework/datamodel/datamodel-container.html (see GeneratedPropertyContainer)
Related
I've got a strange problem with SimplePager of DataTable in GWT 2.7.0
I created a DataTable in the View in this way:
private void initCellTable() {
pecMessageCellTable = new CellTable<>();
dataProvider = new ListDataProvider<>();
dataProvider.addDataDisplay(pecMessageCellTable);
pecMessageCellTable.setPageSize(DEFAULT_PAGE_SIZE);
pecMessageCellTable.setVisibleRange(0,DEFAULT_PAGE_SIZE);
pecMessageCellTable.setWidth("100%", true);
pecMessageCellTable.setAutoHeaderRefreshDisabled(true);
pecMessageCellTable.setAutoFooterRefreshDisabled(true);
pecMessageCellTable.setEmptyTableWidget(new NoResults());
//sort handler
ColumnSortEvent.ListHandler<PecMessage> sortHandler = new ColumnSortEvent.ListHandler<>(dataProvider.getList());
pecMessageCellTable.addColumnSortHandler(sortHandler);
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
pager = new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0, true);
pager.setDisplay(pecMessageCellTable);
pager.setVisible(false);
//from
TextColumn<PecMessage> fromColumn = new TextColumn<PecMessage>() {
#Override
public String getValue(PecMessage message) {
return message.getFrom().iterator().next();
}
};
fromColumn.setSortable(true);
pecMessageCellTable.addColumn(fromColumn, "Mittente");
pecMessageCellTable.setColumnWidth(fromColumn, 18, Unit.PCT);
//subject
TextColumn<PecMessage> subjColumn = new TextColumn<PecMessage>() {
#Override
public String getValue(PecMessage message) {
return message.getSubject();
}
};
subjColumn.setSortable(true);
pecMessageCellTable.addColumn(subjColumn, "Oggetto");
//received date
TextColumn<PecMessage> sentDateColumn = new TextColumn<PecMessage>() {
#Override
public String getValue(PecMessage message) {
return DateTimeFormat.getFormat("dd/MM/yy hh:mm:ss").format(message.getReceived());
}
};
sentDateColumn.setSortable(true);
pecMessageCellTable.addColumn(sentDateColumn, "Data Ricezione");
pecMessageCellTable.setColumnWidth(sentDateColumn, 12, Unit.PCT);
ImageCell imageCell=new ImageCell();
Column<PecMessage,String> iconColumn = new Column<PecMessage, String>(imageCell){
#Override
public String getValue(PecMessage object) {
return object.getImageUrl(object);
}
};
pecMessageCellTable.addColumn(iconColumn,"Lock");
pecMessageCellTable.setColumnWidth(iconColumn, 46, Unit.PX);
//delete Message
ButtonCell buttonCell = new ButtonCell(ButtonType.DANGER, IconType.TRASH);
Column<PecMessage, String> deleteBtn = new Column<PecMessage, String>(buttonCell) {
#Override
public String getValue(PecMessage object) {
return "Elimina";
}
};
pecMessageCellTable.addColumn(deleteBtn, "Elimina");
pecMessageCellTable.setColumnWidth(deleteBtn, 9, Unit.PCT);
pecMessageCellTable.setVisible(false);
}
I populated the data provider later in the code acting a little bit on pager:
public void setEmails(Map<String,PecMessage> emails) {
try {
this.emails = emails;
if(pager.isVisible())
pager.startLoading();
if(emails!=null) {
pecMessageCellTable.setVisibleRangeAndClearData(new Range(0, DEFAULT_PAGE_SIZE), true);
List<PecMessage> list=new ArrayList<PecMessage>(emails.values());
dataProvider.setList(list);
pecMessageCellTable.setRowCount(list.size());
}
if(!pecMessageCellTable.isVisible())
pecMessageCellTable.setVisible(true);
loginFildSet.setVisible(false);
loginBtn.setVisible(false);
logoutBtn.setVisible(true);
refreshBtn.setVisible(true);
if(!pager.isVisible())
pager.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
I've also added some handlers for specific click events for the rows of the table. Handling events, I need to update some rows and I can do it in this way:
public void updateLock(PecMessage message){
int i=dataProvider.getList().indexOf(message);
message.setLockedState(0);
dataProvider.getList().set(i, message);
dataProvider.flush();
dataProvider.refresh();
}
When user fires events and modify some elements of the datatable I always call dataProvider.flush() and dataProvider.refresh() but sometimes, the DataTable pagination seems not to work anymore, the SimplePager changes its range values but does not change table pages, the table is freezed and the user is not able to change page anymore.
It happen randomly so it's hard to fix.
Some suggestion on this strange behaviour?
UPDATE 1:
I realize that the error sould be in setEmails() method because the problem happens only if I modify entirely the list in the dataProvider, hope this could restrict investigation area.
I've figured out the problem.
I analyzed better the browser console and I found a specific error related to a java classes:
Mon Feb 13 14:59:29 GMT+100 2017 com.google.gwt.logging.client.LogConfiguration
SEVERE: (TypeError) : Cannot read property 'eQ' of nullcom.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'eQ' of null
at Unknown.ER(Exceptions.java:36)
at Unknown.Nk(PecMessage.java:322)
at Unknown.X(Object.java:66)
at Unknown.VY(HasDataPresenter.java:1017)
at Unknown.aZ(HasDataPresenter.java:1139)
at Unknown.qZ(HasDataPresenter.java:984)
at Unknown.jt(SchedulerImpl.java:185)
at Unknown._s(SchedulerImpl.java:279)
at Unknown.Qs(Impl.java:323)
at Unknown.Ps(Impl.java:314)
at Unknown.anonymous(Impl.java:72)
At PecMessage.java:322 I found that equals() method was not up to date and did not control null values. Some new attributes were added to the object, and other attributes were modified, so I updated equals() and hashCode() methods and now the CellTable seems to work properly.
I'm currently developing an android app that requires data to be inserted into an azure Mobile Service DB. An id string and a first login integer, to be exact. However the following error is being thrown up.
"IllegalArgumentException: The class representing the MobileServiceTable must have a single id property defined"
The id value that I need to insert into the database is being passed back from a fragment interface using passId(). Inside the override of this is where I am attempting to insert the values into azure as shown below.
#Override
public void passId(String id) {
userInstance user = new userInstance();
user.user_id = id;
user.first_login = 0;
mClient.getTable(userInstance.class).insert(user, new TableOperationCallback<userInstance>() {
public void onCompleted(userInstance entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
} else {
// Insert failed
}
}
});
The mClient var represents the MobileServicesClient as shown below
try {
mClient = new MobileServiceClient(
"https://xxxx.azure-mobile.net/",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
this);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
The table name that I am trying to insert the data into is "user_table" if that helps at all.
I hope you're able to help, and thanks in advance for any help you guys give me.
SOLUTION:
Because the Azure Table that I was attempting to add data to auto created an "id" column, the user object that I was using to construct user info to insert into the database had to define an "id" String. As shown below:
public class userInstance {
#com.google.gson.annotations.SerializedName("id")
public String mId;
#com.google.gson.annotations.SerializedName("user_id")
public String mUserId;
#com.google.gson.annotations.SerializedName("first_login")
public int mLogin;
}
We are working for internationalizing an old application with some dirty code. For example, we have an object DTO InstrumentDto:
private String label;
private Quotation quotation;
private ExprQuote quoteExp;
public String getTypeCouponCouru() {
if (this.quoteExp.getCode().equals(Constants.INS_QUOTE_EXPR_PCT_NOMINAL_CPN_INCLUS)
|| this.quoteExp.getCode().equals(Constants.INS_QUOTE_EXPR_PCT_NOMINAL_INTERET)) {
return "Coupon attaché";
} else if(this.quoteExp.getCode().equals(Constants.INS_QUOTE_EXPR_PCT_NOMINAL_PIED_CPN)){
return "Coupon détaché";
} else {
return "";
}
}
public String getFormattedLabel() {
StringBuilder formattedLabel = new StringBuilder(this.label);
Quotation quote = this.quotation;
if (this.quotation != null) {
formattedLabel.append(" ");
formattedLabel.append(FormatUtil.formatDecimal(this.quotation.getCryQuote());
if (this.quoteExp.getType().equals("PERCENT")) {
formattedLabel.append(" %");
} else {
formattedLabel.append(" ");
formattedLabel.append(this.quotation.getCurrency().getCode());
}
formattedLabel.append(" le ");
formattedLabel.append(DateUtil.formatDate(this.quotation.getValoDate()));
}
return formattedLabel.toString();
}
Then, those methods are used on JSPs. For example for getFormattedLabel(), we have :
<s:select name = "orderUnitaryForm.fieldInstrument"
id = "fieldInstrument"
list = "orderUnitaryForm.instrumentList"
listKey = "id"
listValue = "formattedLabel" />
IMO, the first method doesn't have its place on the DTO. We are expecting the view to manage the label to print. And in this view (the JSP), no problem to translate those words.
Additionally, this method is just used in 2 JSP. Not a problem to "repeat" the conditional tests.
But it's more difficult for getFormattedLabel() : this method is used in a lot of JSP, and the building of the formatted label is "complicated". And it's not possible having the i18n service in the DTO.
So how to do that ?
Your code in getFormattedLabel() seems to be business logic.
A DTO is a simple object without any complex test/behavior (see wiki definition).
IMO, you should move this chunk of code to your Action and split your *.properties file like this:
Your *.properties:
message1= {0} % le {1}
message2= {0} {1} le {2}
Your Action:
public MyAction extends ActionSupport {
public String execute(){
//useful code here
InstrumentDto dto = new InstrumentDto();
StringBuilder formattedLabel = new StringBuilder(label);
if (this.quotation != null) {
String cryQuote = FormatUtil.formatDecimal(this.quotation.getCryQuote());
String date = DateUtil.formatDate(this.quotation.getValoDate());
if (this.quoteExp.getType().equals("PERCENT")) {
formattedLabel.append(getText("message1", new String[] { cryQuote, date }));
} else {
String cryCode = this.quotation.getCurrency().getCode();
formattedLabel.append(getText("message2", new String[] { cryQuote, cryCode, date }));
}
}
dto.setFormattedLabel(formattedLabel);
}
}
Hope this will help ;)
I would like to copy note item from one note document to the other using Java below is the my lotus script version of what i want to achive in Java
Sub CopyItem(FromDoc As NotesDocument, ToDoc As NotesDocument, itemName As String)
Dim FromItem As NotesItem
Dim ToItem As NotesItem
If Not (FromDoc.Hasitem(itemName)) Then Exit Sub
Set FromItem = FromDoc.GetFirstItem(itemName)
If Not ToDoc.hasitem(itemName) Then Set ToItem = ToDoc.CreateItem(itemName)
ToItem.Values = FromDoc.Values
End Sub
I have tried the below:
public static void copyAnItem(Document FromDoc, Document ToDoc, String sItemName){
Vector<String> FromItem = new Vector<String>();
Vector<String> ToItem = new Vector<String>();
if(!FromDoc.hasItem((itemName))){
return;
}
FromItem = FromDoc.getItemValue(itemName);
if(!ToDoc.hasItem(sItemName)){
ToItem.add(itemName);
}
ToItem.addAll(FromDoc);
}
public static void copyAnItem(Document fromDoc, Document toDoc, String itemName){
try {
if(fromDoc.hasItem(itemName)) {
toDoc.copyItem(fromDoc.getFirstItem(itemName));
}
} catch (NotesException e) {
// your exception handling
}
}
You can get the whole item including all properties from fromDoc with getFirstItem and can copy it to toDoc with copyItem in just one line of code.
public static void copyAnItem(Document FromDoc, Document ToDoc, String sItemName){
if(FromDoc.hasItem(sItemName)){
ToDoc.replaceItemValue(sItemName, FromDoc.getItemValue(sItemName));
}
}
It won't work with Authors or Readers items. Better the Knut solution :)
I need a wizard which second page content depends on the first page's selection. The first page asks the user the "kind" of filter he wants to create and the second one asks the user to create one filter instance of the selected "kind".
JFace's wizards pages contents (createControl(...) method) are all created when the wizard is open and not when a given page is displayed (this allow JFace to know the wizard size I guess ??).
Because of this, I have to create my second page content BEFORE the wizard is opened BUT I can't since the second page's content depends on the first page selection.
For now the cleaner solution I found consists in creating all (seconds) pages before the wizard is open (with their content) and override the getNextPage() method in the first page's implementation.
The main drawback of that solution is that it can be be expensive when there are many second pages to create.
What do you think about that solution ? How do you manage your wizard's pages ? Is there any cleaner solution I missed ?
The approach is right if you are several other pages which are
completely different one with another
depends on the previous choices made in a previous page
Then you can add the next page dynamically (also as described here)
But if you have just a next page with a dynamic content, you should be able to create that content in the onEnterPage() method
public void createControl(Composite parent)
{
//
// create the composite to hold the widgets
//
this.composite = new Composite(parent, SWT.NONE);
//
// create the desired layout for this wizard page
//
GridLayout layout = new GridLayout();
layout.numColumns = 4;
this.composite.setLayout(layout);
// set the composite as the control for this page
setControl(this.composite);
}
void onEnterPage()
{
final MacroModel model = ((MacroWizard) getWizard()).model;
String selectedKey = model.selectedKey;
String[] attrs = (String[]) model.macroMap.get(selectedKey);
for (int i = 0; i < attrs.length; i++)
{
String attr = attrs[i];
Label label = new Label(this.composite, SWT.NONE);
label.setText(attr + ":");
new Text(this.composite, SWT.NONE);
}
pack();
}
As shown in the eclipse corner article Creating JFace Wizards:
We can change the order of the wizard pages by overwriting the getNextPage method of any wizard page.Before leaving the page, we save in the model the values chosen by the user. In our example, depending on the choice of travel the user will next see either the page with flights or the page for travelling by car.
public IWizardPage getNextPage(){
saveDataToModel();
if (planeButton.getSelection()) {
PlanePage page = ((HolidayWizard)getWizard()).planePage;
page.onEnterPage();
return page;
}
// Returns the next page depending on the selected button
if (carButton.getSelection()) {
return ((HolidayWizard)getWizard()).carPage;
}
return null;
}
We define a method to do this initialization for the PlanePage, onEnterPage() and we invoke this method when moving to the PlanePage, that is in the getNextPage() method for the first page.
If you want to start a new wizard based on your selection on the first page, you can use the JFace base class org.eclipse.jface.wizard.WizardSelectionPage.
The example below shows a list of available wizards defined by an extension point.
When you press Next, the selected wizard is started.
public class ModelSetupWizardSelectionPage extends WizardSelectionPage {
private ComboViewer providerViewer;
private IConfigurationElement selectedProvider;
public ModelSetupWizardSelectionPage(String pageName) {
super(pageName);
}
private class WizardNode implements IWizardNode {
private IWizard wizard = null;
private IConfigurationElement configurationElement;
public WizardNode(IConfigurationElement c) {
this.configurationElement = c;
}
#Override
public void dispose() {
}
#Override
public Point getExtent() {
return new Point(-1, -1);
}
#Override
public IWizard getWizard() {
if (wizard == null) {
try {
wizard = (IWizard) configurationElement
.createExecutableExtension("wizardClass");
} catch (CoreException e) {
}
}
return wizard;
}
#Override
public boolean isContentCreated() {
// TODO Auto-generated method stub
return wizard != null;
}
}
#Override
public void createControl(Composite parent) {
setTitle("Select model provider");
Composite main = new Composite(parent, SWT.NONE);
GridLayout gd = new GridLayout(2, false);
main.setLayout(gd);
new Label(main, SWT.NONE).setText("Model provider");
Combo providerList = new Combo(main, SWT.NONE);
providerViewer = new ComboViewer(providerList);
providerViewer.setLabelProvider(new LabelProvider() {
#Override
public String getText(Object element) {
if (element instanceof IConfigurationElement) {
IConfigurationElement c = (IConfigurationElement) element;
String result = c.getAttribute("name");
if (result == null || result.length() == 0) {
result = c.getAttribute("class");
}
return result;
}
return super.getText(element);
}
});
providerViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
#Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (!selection.isEmpty()
&& selection instanceof IStructuredSelection) {
Object o = ((IStructuredSelection) selection)
.getFirstElement();
if (o instanceof IConfigurationElement) {
selectedProvider = (IConfigurationElement) o;
setMessage(selectedProvider.getAttribute("description"));
setSelectedNode(new WizardNode(selectedProvider));
}
}
}
});
providerViewer.setContentProvider(new ArrayContentProvider());
List<IConfigurationElement> providers = new ArrayList<IConfigurationElement>();
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry
.getExtensionPoint(<your extension point namespace>,<extension point name>);
if (extensionPoint != null) {
IExtension extensions[] = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement configurationElements[] = extension
.getConfigurationElements();
for (IConfigurationElement c : configurationElements) {
providers.add(c);
}
}
}
providerViewer.setInput(providers);
setControl(main);
}
The corresponding wizard class looks like this:
public class ModelSetupWizard extends Wizard {
private ModelSetupWizardSelectionPage wizardSelectionPage;
public ModelSetupWizard() {
setForcePreviousAndNextButtons(true);
}
#Override
public boolean performFinish() {
// Do what you have to do to finish the wizard
return true;
}
#Override
public void addPages() {
wizardSelectionPage = new ModelSetupWizardSelectionPage("Select a wizard");
addPage(wizardSelectionPage);
}
}
Another alternative is to #Override setVisible. You can update page values or add additional widgets at that time.
I have a different solution.
If page depends on the result of page 1, create a variable and pass it into to first page, when that wizard page has the option from the user, then the last thing before the page is closed is to set the variable to the required value.
Then pass this variable to wizard, then pass it to the next wizard page. Then do a simple if statement and that way you get both choices together.
Remember that in most code there is only a small difference in the user options, so remember not to get bogged down in duplicating your code.