blob: 66f98fb799e6fc3a381c5a65a13f2f98dfb6ca10 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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
*
<<<<<<< HEAD
* Contributors:
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Contributors:
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.examples.robotic_arm.ui.parts;
import org.eclipse.apogy.core.invocator.InvocatorSession;
import org.eclipse.apogy.core.invocator.ui.parts.AbstractSessionBasedPart;
import org.eclipse.apogy.examples.robotic_arm.ApogyExamplesRoboticArmFacade;
import org.eclipse.apogy.examples.robotic_arm.ApogyExamplesRoboticArmPackage;
import org.eclipse.apogy.examples.robotic_arm.ui.composites.RoboticArmControlComposite;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
public class RoboticArmExampleDashboardPart extends AbstractSessionBasedPart {
private RoboticArmControlComposite roboticArmControlComposite;
private Adapter activeRoboticArmAdapter;
@Override
protected void newInvocatorSession(InvocatorSession invocatorSession) {
if (invocatorSession != null) {
this.roboticArmControlComposite.setRoboticArm(ApogyExamplesRoboticArmFacade.INSTANCE.getActiveRoboticArm());
} else {
this.roboticArmControlComposite.setRoboticArm(null);
}
}
@Override
public void userPostConstruct(MPart mPart) {
ApogyExamplesRoboticArmFacade.INSTANCE.eAdapters().add(getActiveRoboticArmAdapter());
}
@Override
public void userPreDestroy(MPart mPart) {
ApogyExamplesRoboticArmFacade.INSTANCE.eAdapters().remove(getActiveRoboticArmAdapter());
}
@Override
protected void createContentComposite(Composite parent, int style) {
parent.setLayout(new FillLayout());
this.roboticArmControlComposite = new RoboticArmControlComposite(parent, SWT.BORDER);
this.roboticArmControlComposite.setRoboticArm(ApogyExamplesRoboticArmFacade.INSTANCE.getActiveRoboticArm());
}
protected Adapter getActiveRoboticArmAdapter() {
if (this.activeRoboticArmAdapter == null) {
this.activeRoboticArmAdapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getNotifier() instanceof ApogyExamplesRoboticArmFacade) {
int featureID = msg.getFeatureID(ApogyExamplesRoboticArmFacade.class);
switch (featureID) {
case ApogyExamplesRoboticArmPackage.APOGY_EXAMPLES_ROBOTIC_ARM_FACADE__ACTIVE_ROBOTIC_ARM:
if (RoboticArmExampleDashboardPart.this.roboticArmControlComposite != null
&& !RoboticArmExampleDashboardPart.this.roboticArmControlComposite.isDisposed()) {
// This needs to be done on the UI thread.
RoboticArmExampleDashboardPart.this.roboticArmControlComposite.getDisplay()
.asyncExec(new Runnable() {
@Override
public void run() {
RoboticArmExampleDashboardPart.this.roboticArmControlComposite
.setRoboticArm(ApogyExamplesRoboticArmFacade.INSTANCE
.getActiveRoboticArm());
}
});
}
break;
default:
break;
}
}
}
};
}
return this.activeRoboticArmAdapter;
}
}