
com.liferay.application.list.adapter.PortletPanelAppAdapterServiceTrackerCustomizer Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.application.list.adapter;
import com.liferay.application.list.PanelApp;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HashMapDictionary;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.util.PortletCategoryUtil;
import java.util.Dictionary;
import java.util.Map;
import javax.portlet.Portlet;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* @author Adolfo Pérez
*/
public class PortletPanelAppAdapterServiceTrackerCustomizer
implements ServiceTrackerCustomizer {
public PortletPanelAppAdapterServiceTrackerCustomizer(
BundleContext bundleContext,
Map, ServiceRegistration>
serviceRegistrations) {
_bundleContext = bundleContext;
_serviceRegistrations = serviceRegistrations;
}
@Override
public PanelApp addingService(ServiceReference serviceReference) {
String portletId = (String)serviceReference.getProperty(
"javax.portlet.name");
if (Validator.isNull(portletId)) {
return null;
}
String controlPanelCategory = (String)serviceReference.getProperty(
"com.liferay.portlet.control-panel-entry-category");
if (Validator.isNull(controlPanelCategory)) {
return null;
}
PanelApp portletPanelAppAdapter = new PortletPanelAppAdapter(portletId);
Dictionary panelAppProperties =
new HashMapDictionary<>();
panelAppProperties.put(
"panel.category.key",
PortletCategoryUtil.getPortletCategoryKey(controlPanelCategory));
Integer serviceRanking = getServiceRanking(serviceReference);
if (serviceRanking != null) {
panelAppProperties.put("service.ranking", serviceRanking);
}
ServiceRegistration serviceRegistration =
_bundleContext.registerService(
PanelApp.class, portletPanelAppAdapter, panelAppProperties);
_serviceRegistrations.put(serviceReference, serviceRegistration);
return portletPanelAppAdapter;
}
@Override
public void modifiedService(
ServiceReference serviceReference, PanelApp panelApp) {
removedService(serviceReference, panelApp);
addingService(serviceReference);
}
@Override
public void removedService(
ServiceReference serviceReference, PanelApp panelApp) {
ServiceRegistration serviceRegistration =
_serviceRegistrations.remove(serviceReference);
serviceRegistration.unregister();
}
protected Integer getServiceRanking(
ServiceReference serviceReference) {
String controlPanelEntryWeight = (String)serviceReference.getProperty(
"com.liferay.portlet.control-panel-entry-weight");
if (Validator.isNotNull(controlPanelEntryWeight)) {
return (int)Math.ceil(
GetterUtil.getDouble(controlPanelEntryWeight) * 100);
}
return null;
}
private final BundleContext _bundleContext;
private final Map, ServiceRegistration>
_serviceRegistrations;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy