org.jboss.as.console.client.shared.subsys.osgi.runtime.BundleRuntimeView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of switchyard-console-as7-core
Show all versions of switchyard-console-as7-core
Bundles the core AS7 console as a GWT module. Includes minor customizations to support extensions.
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.jboss.as.console.client.shared.subsys.osgi.runtime;
import com.google.gwt.cell.client.ActionCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.cell.client.ImageResourceCell;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.ColumnSortEvent.Handler;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.shared.dispatch.DispatchAsync;
import org.jboss.as.console.client.shared.runtime.RuntimeBaseAddress;
import org.jboss.as.console.client.shared.subsys.osgi.runtime.model.OSGiBundle;
import org.jboss.as.console.client.shared.viewframework.AbstractEntityView;
import org.jboss.as.console.client.shared.viewframework.EntityToDmrBridge;
import org.jboss.as.console.client.shared.viewframework.EntityToDmrBridgeImpl;
import org.jboss.as.console.client.shared.viewframework.FrameworkButton;
import org.jboss.as.console.client.shared.viewframework.FrameworkView;
import org.jboss.as.console.client.widgets.forms.ApplicationMetaData;
import org.jboss.as.console.client.widgets.tables.ButtonCell;
import org.jboss.ballroom.client.widgets.forms.Form;
import org.jboss.ballroom.client.widgets.forms.FormAdapter;
import org.jboss.ballroom.client.widgets.icons.Icons;
import org.jboss.ballroom.client.widgets.tables.DefaultCellTable;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.ballroom.client.widgets.window.Feedback;
import org.jboss.dmr.client.ModelDescriptionConstants;
import org.jboss.dmr.client.ModelNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author David Bosschaert
*/
public class BundleRuntimeView extends AbstractEntityView implements FrameworkView {
private final EntityToDmrBridgeImpl bridge;
private DefaultCellTable bundleTable;
private OSGiRuntimePresenter presenter;
private MyListHandler sortHandler;
public BundleRuntimeView(ApplicationMetaData propertyMetaData, DispatchAsync dispatcher) {
super(OSGiBundle.class, propertyMetaData, EnumSet.allOf(FrameworkButton.class));
bridge = new EntityToDmrBridgeImpl(propertyMetaData, OSGiBundle.class, this, dispatcher) {
@Override
protected void onLoadEntitiesSuccess(ModelNode response) {
if (response.get(ModelDescriptionConstants.RESULT).asList().isEmpty()) {
presenter.askToActivateSubsystem();
} else {
super.onLoadEntitiesSuccess(response);
}
}
};
}
@Override
public Widget createWidget() {
Widget widget = createEmbeddableWidget();
sortHandler.setList(entityEditor.getDataProvider().getList());
return widget;
}
@Override
protected ToolStrip createToolStrip() {
ToolStrip toolStrip = super.createToolStrip();
ToolButton refreshBtn = new ToolButton(Console.CONSTANTS.common_label_refresh(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
initialLoad(RuntimeBaseAddress.get());
}
});
refreshBtn.ensureDebugId(Console.DEBUG_CONSTANTS.debug_label_refresh_bundleRuntimeView());
toolStrip.addToolButtonRight(refreshBtn);
return toolStrip;
}
@Override
public EntityToDmrBridge getEntityBridge() {
return bridge;
}
@Override
protected DefaultCellTable makeEntityTable() {
bundleTable = new DefaultCellTable(8);
sortHandler = new MyListHandler();
TextColumn idColumn = new TextColumn() {
@Override
public String getValue(OSGiBundle record) {
return record.getName();
}
};
idColumn.setSortable(true);
sortHandler.setComparator(idColumn, new Comparator() {
@Override
public int compare(OSGiBundle o1, OSGiBundle o2) {
return new Long(o1.getName()).compareTo(new Long(o2.getName()));
}
});
bundleTable.addColumn(idColumn, Console.CONSTANTS.subsys_osgi_bundleID());
TextColumn symbolicNameColumn = new TextColumn() {
@Override
public String getValue(OSGiBundle record) {
return record.getSymbolicName();
}
};
symbolicNameColumn.setSortable(true);
sortHandler.setComparator(symbolicNameColumn, new Comparator() {
@Override
public int compare(OSGiBundle o1, OSGiBundle o2) {
return o1.getSymbolicName().compareTo(o2.getSymbolicName());
}
});
bundleTable.addColumn(symbolicNameColumn, Console.CONSTANTS.subsys_osgi_bundleSymbolicName());
TextColumn versionColumn = new TextColumn() {
@Override
public String getValue(OSGiBundle record) {
return record.getVersion();
}
};
bundleTable.addColumn(versionColumn, Console.CONSTANTS.subsys_osgi_bundleVersion());
Column stateColumn = new Column(new ImageResourceCell()) {
@Override
public ImageResource getValue(OSGiBundle bundle) {
if ("ACTIVE".equals(bundle.getState()))
return Icons.INSTANCE.status_good();
if ("STARTING".equals(bundle.getState()))
return Icons.INSTANCE.status_warn();
if ("RESOLVED".equals(bundle.getState()))
return Icons.INSTANCE.status_none();
// default
return Icons.INSTANCE.status_none();
}
};
stateColumn.setSortable(true);
sortHandler.setComparator(stateColumn, new Comparator() {
@Override
public int compare(OSGiBundle o1, OSGiBundle o2) {
List order = Arrays.asList("RESOLVED", "STARTING", "ACTIVE");
Integer i1 = order.indexOf(o1.getState());
Integer i2 = order.indexOf(o2.getState());
return i1.compareTo(i2);
}
});
bundleTable.addColumn(stateColumn, Console.CONSTANTS.subsys_osgi_bundleState());
class BundleColumn extends Column {
public BundleColumn(Cell cell) {
super(cell);
}
@Override
public OSGiBundle getValue(OSGiBundle record) {
return record;
}
};
ButtonCell startCell = new ButtonCell(Console.CONSTANTS.common_label_start(), new ActionCell.Delegate() {
@Override
public void execute(OSGiBundle bundle) {
if ("fragment".equals(bundle.getType())) {
Feedback.alert(Console.CONSTANTS.subsys_osgi(), Console.MESSAGES.subsys_osgi_cant_start_fragment(bundle.getSymbolicName()));
} else {
presenter.startBundle(bundle);
}
}
});
final ButtonCell stopCell = new ButtonCell(Console.CONSTANTS.common_label_stop(), new ActionCell.Delegate() {
@Override
public void execute(OSGiBundle bundle) {
if ("fragment".equals(bundle.getType())) {
Feedback.alert(Console.CONSTANTS.subsys_osgi(), Console.MESSAGES.subsys_osgi_cant_stop_fragment(bundle.getSymbolicName()));
} else {
presenter.stopBundle(bundle);
}
}
});
List> buttonCells = new ArrayList>();
buttonCells.add(new BundleColumn(startCell));
buttonCells.add(new BundleColumn(stopCell));
BundleColumn myColumn = new BundleColumn(new CompositeCell(buttonCells));
bundleTable.addColumn(myColumn, Console.CONSTANTS.common_label_action());
bundleTable.addColumnSortHandler(sortHandler);
bundleTable.getColumnSortList().push(idColumn); // initial sort is on bundle ID
return bundleTable;
}
@Override
protected FormAdapter makeAddEntityForm() {
return new Form(OSGiBundle.class); // Empty form, cannot create a bundle here
}
@Override
protected String getEntityDisplayName() {
return Console.CONSTANTS.subsys_osgi_bundles();
}
@Override
public void refresh() {
super.refresh();
// Make sure the new values are properly sorted
ColumnSortEvent.fire(bundleTable, bundleTable.getColumnSortList());
}
public void setPresenter(OSGiRuntimePresenter presenter) {
this.presenter = presenter;
}
// This handler is similar to ColumnSortEvent.ListHandler except that it allows the list to be set after construction
// This class is generic and could move to a more common place if useful.
public static class MyListHandler implements Handler {
private final Map, Comparator> comparators = new HashMap, Comparator>();
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public void onColumnSort(ColumnSortEvent event) {
// Get the sorted column.
Column column = event.getColumn();
if (column == null) {
return;
}
// Get the comparator.
final Comparator comparator = comparators.get(column);
if (comparator == null) {
return;
}
// Sort using the comparator.
if (event.isSortAscending()) {
Collections.sort(list, comparator);
} else {
Collections.sort(list, new Comparator() {
public int compare(T o1, T o2) {
return -comparator.compare(o1, o2);
}
});
}
}
public void setComparator(Column column, Comparator comparator) {
comparators.put(column, comparator);
}
}
}