blob: 49b867dc15675b3a1022aebd3dca9fb85090c90f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2014 TwelveTone LLC and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Steven Spungin <steven@spungin.tv> - initial API and implementation
*******************************************************************************/
package aeri.rcp;
import static aeri.rcp.DemoSingleServerWorkflow.*;
import static org.eclipse.e4.core.contexts.ContextInjectionFactory.make;
import static org.eclipse.epp.logging.aeri.core.SystemControl.registerHandlers;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.UUID;
import org.apache.commons.lang3.SystemUtils;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.epp.logging.aeri.core.IModelFactory;
import org.eclipse.epp.logging.aeri.core.IServerConnection;
import org.eclipse.epp.logging.aeri.core.ISystemSettings;
import org.eclipse.epp.logging.aeri.core.SystemControl;
import org.eclipse.epp.logging.aeri.core.filters.DecoratingDebugFilter;
import org.eclipse.epp.logging.aeri.core.filters.NoErrorStatusFilter;
import org.eclipse.epp.logging.aeri.core.filters.RecentlySeenFilter;
import org.eclipse.epp.logging.aeri.core.filters.SystemEnabledFilter;
import org.eclipse.epp.logging.aeri.core.util.LogListener;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import aeri.rcp.handlers.NotifyConfigureSystemHandler;
import aeri.rcp.handlers.NotifyLogEventHandler;
import aeri.rcp.handlers.NotifyServerResponseHandler;
/**
* This is a stub implementation containing e4 LifeCycle annotated methods.<br />
* There is a corresponding entry in <em>plugin.xml</em> (under the <em>org.eclipse.core.runtime.products' extension point</em>) that
* references this class.
**/
@SuppressWarnings("restriction")
public class E4LifeCycle {
@PostContextCreate
void postContextCreate(IEclipseContext workbenchContext) {
// Initialize the system's DI context as child of the normal workbench to allow (potential) access to OSGI services, application
// services etc. Not used here.
IEclipseContext context = SystemControl.getSystemContext();
context.setParent(workbenchContext);
// register a couple of standard handlers - usually referenced in the workflow class
registerHandlers(NotifyLogEventHandler.class, NotifyConfigureSystemHandler.class, NotifyServerResponseHandler.class);
// configure the system settings (hardcoded here)
context.set(ISystemSettings.class, createSettings());
// register the (dummy console log) server where all events should be sent to
context.set(IServerConnection.class, createServer());
context.set(DemoNotificationSupport.class.getName(), make(DemoNotificationSupport.class, context));
context.set(CTX_STATE_REVIEW_IN_PROGRESS, false);
context.declareModifiable(CTX_STATE_REVIEW_IN_PROGRESS);
context.set(CTX_STATE_SETUP_IN_PROGRESS, false);
context.declareModifiable(CTX_STATE_SETUP_IN_PROGRESS);
context.set(CTX_STATE_NOTIFICATION_IN_PROGRESS, false);
context.declareModifiable(CTX_STATE_NOTIFICATION_IN_PROGRESS);
// create the controller and (implicitly with this call) register it with the IEventBroker
context.set(DemoSingleServerWorkflow.class, make(DemoSingleServerWorkflow.class, context));
context.get(DemoSingleServerWorkflow.class);
// Register the log listener:
LogListener listener = new LogListener(createStatusFilters(), context.get(IEventBroker.class));
Platform.addLogListener(listener);
// optional: put it into the system context for later reference:
context.set(LogListener.class, listener);
}
private ISystemSettings createSettings() {
ISystemSettings settings = IModelFactory.eINSTANCE.createSystemSettings();
settings.setAnonymousId(getStableSystemId());
settings.setReporterName(SystemUtils.USER_NAME);
// XXX for demo purpose. Effectively disables the RecentlySeenFilter
settings.setDebugEnabled(true);
return settings;
}
private String getStableSystemId() {
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
return UUID.nameUUIDFromBytes(mac).toString();
} catch (Exception e) {
return "error";
}
}
private Predicate<IStatus> createStatusFilters() {
Predicate<? super IStatus>[] statusPredicates = DecoratingDebugFilter.decorate(
// @formatter:off
new NoErrorStatusFilter(),
new SystemEnabledFilter(),
new RecentlySeenFilter()
// @formatter:on
);
Predicate<IStatus> statusFilters = Predicates.and(statusPredicates);
return statusFilters;
}
private IServerConnection createServer() {
return new DemoServerConnection();
}
}