[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model ...
Robert Stryker
rawblem at gmail.com
Wed Nov 15 17:26:56 EST 2006
User: rawb
Date: 06/11/15 17:26:56
Added: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model
EventLogModel.java
Log:
Rebuilt the event log API and fixed some UI bugs preventing an efficient refresh of the tree.
Revision Changes Path
1.1 date: 2006/11/15 22:26:56; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/model/EventLogModel.java
Index: EventLogModel.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This 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 software 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.model;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
/**
*
* @author rob.stryker at jboss.com
*/
public class EventLogModel {
private static EventLogModel instance;
public static EventLogModel getDefault() {
if( instance == null )
instance = new EventLogModel();
return instance;
}
public static ServerEventModel getModel(IServer server) {
return getModel(server.getId());
}
public static ServerEventModel getModel(String serverId) {
return getDefault().getEventModel(serverId);
}
public static void markChanged(EventLogTreeItem item) {
SimpleTreeItem root = item.getRoot();
if( root != null && root instanceof EventLogRoot ) {
String serverId = ((EventLogRoot)root).getServerId();
getDefault().fireItemChanged(serverId, item);
}
}
public static interface IEventLogListener {
public void eventModelChanged(String serverId, EventLogTreeItem changed);
}
private HashMap serverToModel;
private ArrayList listeners;
public EventLogModel() {
serverToModel = new HashMap();
listeners = new ArrayList();
}
public void addListener(IEventLogListener listener) {
if( !listeners.contains(listener)) listeners.add(listener);
}
public void removeListener(IEventLogListener listener) {
listeners.remove(listener);
}
public void fireItemChanged(String serverId, EventLogTreeItem changed) {
IEventLogListener[] listenerArray = (IEventLogListener[]) listeners.toArray(new IEventLogListener[listeners.size()]);
for( int i = 0; i < listenerArray.length; i++ ) {
listenerArray[i].eventModelChanged(serverId, changed);
}
}
public ServerEventModel getEventModel(String serverId) {
if( serverToModel.get(serverId) != null )
return (ServerEventModel)serverToModel.get(serverId);
ServerEventModel m = new ServerEventModel(serverId);
serverToModel.put(serverId, m);
return m;
}
public static class ServerEventModel {
private String id;
private EventLogRoot root;
protected ServerEventModel(String serverId) {
this.id = serverId;
root = new EventLogRoot(this);
}
public String getId() {
return id;
}
public EventLogRoot getRoot() {
return root;
}
}
public static class EventLogTreeItem extends SimpleTreeItem {
private String type;
public EventLogTreeItem(SimpleTreeItem parent, String type) {
super(parent, null);
this.type = type;
}
public EventLogTreeItem(SimpleTreeItem parent, Object data, String type) {
super(parent, data);
this.type = type;
}
public String getType() {
return type;
}
public EventLogTreeItem getEventRoot() {
SimpleTreeItem item = this;
while(item.getParent() != null && item.getParent() instanceof EventLogTreeItem)
item = item.getParent();
return (EventLogTreeItem)item;
}
}
public static class EventLogRoot extends EventLogTreeItem {
protected ServerEventModel model;
public EventLogRoot(ServerEventModel model) {
super(null, null, "jboss.event.root");
this.model = model;
}
public ServerEventModel getModel() {
return model;
}
public String getServerId() {
return model.getId();
}
}
}
More information about the jboss-cvs-commits
mailing list