I'm doing a Liferay portal with different portlets on it in different columns created in a Liferay Layout.
My question is: How can I change programmatically (in java) the column to which a portlet belongs?
I've tried with this:
long userId = themeDisplay.getUserId();
long groupId = themeDisplay.getLayout().getGroupId();
Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, true, currentFriendlyURL);
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
layoutTypePortlet.removePortletId(userId, iniPortletName);
String portletInstanceId = layoutTypePortlet.addPortletId(userId, iniPortletName, newColumn, position, true);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
It works, but with this code, I delete the portlet and then, I create a new instance, and I don't want that.
How can I update the position of same instance of the portlet?
Thank you.
Ok, I found it.
If you want to keep the same instance, you can use the movePortletId(userId, portletId, newColumn, position) method.
String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
layoutTypePortlet.movePortletId(userId, portletId, finColumn, position);
You need to use the portletId instead of portletName, that identifies all the portlets with the same name.
https://docs.liferay.com/portal/6.2/javadocs/src-html/com/liferay/portal/model/LayoutTypePortlet.html
Thank you.
Related
Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);
I'm working at a Plugin for a Eclipse-RCP. There is another Plugin with a TreeViewer and I want to select an Item from my Plugin. I don't know how to get access it, is this even possible?
I think can get the correct view with:
IViewReference home;
IViewReference [] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (int i = 0; i < viewRefs.length; i++) {
if(viewRefs[i].getId()==myid){
home = viewRefs[i];
break;
}
}
But home is not a TreeViewer and I cant cast it. How can I get the TreeViewer?
home.getTreeViewer() //Doesn't work cause of casting issues
I am a newbie to rcp, so I would be nice for some explanation.
You need to find your view using:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("your view id");
You can then cast the view part to your view class and call a method that you write on that class:
if (viewPart != null) {
MyViewClass myViewPart = (MyViewClass)viewPart;
myViewPart.getTreeViewer();
}
where MyViewClass is your ViewPart class. You will have to write the getTreeViewer method.
If the view is not currently open you can use showView:
viewPart = page.showView("your view id");
You have to cast home to the type of your other view. Then you can get the TreeViewer.
You can find the ViewPart directly from your active IWorkbenchPage using IWorkbenchPage#findView(java.lang.String).
If you have the object you want to be selected, get the View's Site, get the Site's selection provider, and then tell the selection provider what should be selected (with a StructuredSelection instance containing the object). This only works if the tree, or whatever is in the part (you shouldn't have to care or know that it's a tree), actually contains the object that you're telling it to select.
In my table I have a column defined as follows:
table.addContainerProperty("Skill", Label.class, null);
When I export this table using TableExport addon
Button excelExportButton = new Button("Export to Excel", click -> {
ExcelExport excelExport;
excelExport = new ExcelExport(table);
excelExport.setReportTitle("Foo Bar");
excelExport.setDisplayTotals(false);
excelExport.export();
});
I get com.vaadin.ui.Label#6a3f610e instead of text. How can I fix this?
Thank you in advance for help.
I have never used the TableExport addon but I have two solutions in my mind:
Use String as a property type: table.addContainerProperty("Skill", String.class, null);
Create your own extended Label and override the toString() method to return the value you want to see in exported excel sheets.
I'm trying to send text to a view that I know the id of. It seems enterText() wants an int, but all I have is a view.
solo.enterText(solo.getView(R.id.et_firstname_insurance), firstName);
Ideas? I read the API documentation and can't figure it out.
I figured it out with the help of my coworker. This turns the view into an EditText object, which can be passed into one of the flavors of enterText:
public static EditText getEditText(int i) {
return (EditText) solo.getCurrentActivity().findViewById(i);
}
EditText eFn = RobotiumHelpers.getEditText(R.id.et_firstname_insurance);
solo.enterText(eFn, firstName);
I'm pretty sure that this is not allowed. Robotium is testing purposes and if you're changing the whole state of the activity externally than that defeats the purpose and might possibly have the ability to do damage. Now if you're talking about entering text in something that is editable than the int is the editable field number. Check out the tutorial
you can assign this to a view as view1 and then you can use
solo.enterText(view1, firstName);
and if that also doesn't work try using solo.clickOnView(view1);
and after that solo.enterText(view1, firstName);
What worked for me - assertTrue("btnUseEmailToLogin View is not visible", (solo.getView("idName") ).isShown() == true);
Where idName - is the id of desired view to check
Suppose I have Layout instance (in Java or JSP) and I want to get it's URL.
Layout represents a page. Page has "friendly URL" and I can get it by friendlyURL property.
But what about FULL url?
I can also get scopeGroup's friendly url, where
Group scopeGroup = themeDisplay.getScopeGroup();
and obtain more short part, which is also not full.
Company.getPortalURL
also does not contain all other text (does not include port and "/web" parts).
Inside \ROOT\html\portlet\layouts_admin\layout\details.jsp I found the following code to build it
boolean privateLayout = ((Boolean)renderRequest.getAttribute("edit_pages.jsp-privateLayout")).booleanValue();
Layout selLayout = (Layout)renderRequest.getAttribute("edit_pages.jsp-selLayout");
StringBuilder friendlyURLBase = new StringBuilder();
friendlyURLBase.append(themeDisplay.getPortalURL());
LayoutSet layoutSet = selLayout.getLayoutSet();
String virtualHostname = layoutSet.getVirtualHostname();
if (Validator.isNull(virtualHostname) || (friendlyURLBase.indexOf(virtualHostname) == -1)) {
friendlyURLBase.append(scopeGroup.getPathFriendlyURL(privateLayout, themeDisplay));
friendlyURLBase.append(scopeGroup.getFriendlyURL());
}
but this code is based on strange parameters edit_pages.jsp-privateLayout and edit_pages.jsp-selLayout which I am afraid will not be accessible in normal portlet.
So, how to obtain FULL URL of page instance?
Try this:
PortalUtil.getLayoutFullURL(layout, themeDisplay)