blob: ac19c76203c89c60e186c765a3dcfca220b7d4e8 [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
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque,
<<<<<<< HEAD
* Sebastien Gemme
*
=======
* Sebastien Gemme - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.topology.ui.views;
import org.eclipse.apogy.common.topology.ui.Activator;
import org.eclipse.apogy.common.topology.ui.composites.NodePresentationListComposite;
import org.eclipse.apogy.common.topology.ui.composites.TopologyPresentationSetListComposite;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.progress.UIJob;
public class TopologyPresentationRegistryView extends ViewPart {
private NodePresentationListComposite nodePresentationListComposite;
private TopologyPresentationSetListComposite topologyPresentationSetListComposite;
private Adapter topologyPresentationRegistryAdapter = null;
@Override
public void createPartControl(Composite parent) {
GridLayout gridLayout = new GridLayout(2, true);
parent.setLayout(gridLayout);
Label nodeListLabel = new Label(parent, SWT.NONE);
GridData gridData1 = new GridData(SWT.LEFT, SWT.FILL, true, false, 1, 1);
nodeListLabel.setLayoutData(gridData1);
nodeListLabel.setText("Node Presentations");
Label topologyPresentationSetLabel = new Label(parent, SWT.NONE);
GridData gridData2 = new GridData(SWT.LEFT, SWT.FILL, true, false, 1, 1);
topologyPresentationSetLabel.setLayoutData(gridData2);
topologyPresentationSetLabel.setText("Topology Presentation Sets");
this.nodePresentationListComposite = new NodePresentationListComposite(parent, SWT.NONE);
GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
this.nodePresentationListComposite.setLayoutData(gridData3);
this.nodePresentationListComposite
.setNodePresentationSet(Activator.getTopologyPresentationRegistry().getNodePresentationList());
this.topologyPresentationSetListComposite = new TopologyPresentationSetListComposite(parent, SWT.NONE);
GridData gridData4 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
this.topologyPresentationSetListComposite.setLayoutData(gridData4);
this.topologyPresentationSetListComposite.setTopologyPresentationSet(
Activator.getTopologyPresentationRegistry().getTopologyPresentationSetList());
Activator.getTopologyPresentationRegistry().eAdapters().add(getTopologyPresentationRegistryAdapter());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Activator.getTopologyPresentationRegistry().eAdapters()
.remove(getTopologyPresentationRegistryAdapter());
TopologyPresentationRegistryView.this.nodePresentationListComposite.setNodePresentationSet(null);
TopologyPresentationRegistryView.this.topologyPresentationSetListComposite
.setTopologyPresentationSet(null);
}
});
}
@Override
public void setFocus() {
}
private Adapter getTopologyPresentationRegistryAdapter() {
if (this.topologyPresentationRegistryAdapter == null) {
this.topologyPresentationRegistryAdapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
// Force update on topologyPresentationSetListComposite
UIJob job = new UIJob("TopologyPresentationRegistryView Update") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (!TopologyPresentationRegistryView.this.nodePresentationListComposite.isDisposed())
TopologyPresentationRegistryView.this.nodePresentationListComposite
.setNodePresentationSet(
Activator.getTopologyPresentationRegistry().getNodePresentationList());
if (!TopologyPresentationRegistryView.this.topologyPresentationSetListComposite
.isDisposed())
TopologyPresentationRegistryView.this.topologyPresentationSetListComposite
.setTopologyPresentationSet(Activator.getTopologyPresentationRegistry()
.getTopologyPresentationSetList());
return Status.OK_STATUS;
}
};
job.schedule();
}
};
}
return this.topologyPresentationRegistryAdapter;
}
}