Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Release_14.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddieAkeroyd committed Jan 17, 2024
2 parents 4f374d2 + 9e42850 commit 398d64f
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 74 deletions.
3 changes: 2 additions & 1 deletion base/uk.ac.stfc.isis.ibex.ui.moxas/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.201.200",
org.hamcrest.library;bundle-version="1.3.0",
uk.ac.stfc.isis.ibex.model;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.epics;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.configserver;bundle-version="1.0.0"
uk.ac.stfc.isis.ibex.configserver;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.e4.ui;bundle-version="1.0.0"
Export-Package: uk.ac.stfc.isis.ibex.ui.moxas.views
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/*
* This file is part of the ISIS IBEX application. Copyright (C) 2012-2023
* Science & Technology Facilities Council. All rights reserved.
*
* This program is distributed in the hope that it will be useful. This program
* and the accompanying materials are made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution. EXCEPT AS
* EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM AND
* ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more
* details.
*
* You should have received a copy of the Eclipse Public License v1.0 along with
* this program; if not, you can obtain a copy from
* https://www.eclipse.org/org/documents/epl-v10.php or
* http://opensource.org/licenses/eclipse-1.0.php
*/

/*
* Copyright (C) 2013-2014 Research Councils UK (STFC)
*
* This file is part of the Instrument Control Project at ISIS.
*
* This code and information are provided "as is" without warranty of any kind,
* either expressed or implied, including but not limited to the implied
* warranties of merchantability and/or fitness for a particular purpose.
*/

package uk.ac.stfc.isis.ibex.ui.moxas.views;

import java.beans.PropertyChangeEvent;
Expand All @@ -19,8 +47,11 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.wb.swt.SWTResourceManager;


import uk.ac.stfc.isis.ibex.configserver.configuration.Ioc;

Expand All @@ -36,6 +67,7 @@ public class MoxaInfoPanel extends Composite {
private static final int COLUMN_WIDTH = 500;
private static final int COLUMN_WIDTH_NARROW = 150;

private static final String UP_STATUS = "up";
/**
* The constructor.
*
Expand All @@ -48,67 +80,11 @@ public MoxaInfoPanel(Composite parent, int style, MoxasViewModel model) {
setLayout(new GridLayout(1, false));

final var viewer = new TreeViewer(this, SWT.FULL_SELECTION);
TreeViewerColumn moxaPortColumn = new TreeViewerColumn(viewer, SWT.NONE);
moxaPortColumn.getColumn().setText("Physical MOXA port");
moxaPortColumn.getColumn().setWidth(COLUMN_WIDTH);

moxaPortColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof MoxaList) {
MoxaList list = MoxaList.class.cast(element);
String name = list.name;
return name;
} else {
MoxaModelObject p = (MoxaModelObject) element;
return p.getPhysPort();
}
}
});
TreeViewerColumn comPortColumn = new TreeViewerColumn(viewer, SWT.NONE);
comPortColumn.getColumn().setText("COM port");
comPortColumn.getColumn().setWidth(COLUMN_WIDTH_NARROW);

comPortColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject p = (MoxaModelObject) element;
return p.getComPort();
}
});
TreeViewerColumn iocColumn = new TreeViewerColumn(viewer, SWT.NONE);
iocColumn.getColumn().setText("Connected IOC");
iocColumn.getColumn().setWidth(COLUMN_WIDTH);

iocColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Color getForeground(Object element) {
// Change the text colour of cells where a port is connected to multiple IOCs
if (element instanceof MoxaModelObject) {
MoxaModelObject p = (MoxaModelObject) element;
List<Ioc> iocs = p.getIocs();

if (iocs.size() > 1) {
return new Color(255, 0, 0);
}
}
return super.getForeground(element);
}

@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject p = (MoxaModelObject) element;
List<Ioc> iocs = p.getIocs();

return iocs.stream().map(Ioc::getName).collect(joining(", "));
}
});
makePhysicalPortColumn(viewer);
makeComPortColumn(viewer);
makeConnectedIOCColumn(viewer);
makeStatusColumn(viewer);
makeAdditionInfoColumn(viewer);

viewer.setContentProvider(new MoxaTableContentProvider());

Expand All @@ -131,10 +107,10 @@ public void treeExpanded(TreeEvent e) {
TreeItem item = (TreeItem) e.item;
model.addExpanded(item.getText());
}
});
});

Composite expansionComposite = new Composite(this, SWT.FILL);
expansionComposite.setLayout(new GridLayout(3, true));
expansionComposite.setLayout(new GridLayout(5, true));
expandButton = new Button(expansionComposite, SWT.NONE);
expandButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
expandButton.setText("\u25BC Expand All");
Expand All @@ -155,6 +131,11 @@ public void widgetSelected(SelectionEvent e) {
}
});

Label refreshLabel = new Label(expansionComposite, SWT.NONE);
refreshLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 3, 1));
refreshLabel.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
refreshLabel.setText("Items will refresh every 30 seconds");

model.addUiThreadPropertyChangeListener("moxaMappings", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Expand All @@ -164,8 +145,8 @@ public void propertyChange(PropertyChangeEvent evt) {
model.refresh();
}
});
model.addUiThreadPropertyChangeListener("expanded", new PropertyChangeListener() {

model.addUiThreadPropertyChangeListener("expanded", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
// Re-expand previously expanded items
Expand All @@ -186,4 +167,143 @@ public void propertyChange(PropertyChangeEvent evt) {
});
}

/**
* @param viewer
*/
private void makeComPortColumn(final TreeViewer viewer) {
TreeViewerColumn comPortColumn = new TreeViewerColumn(viewer, SWT.NONE);
comPortColumn.getColumn().setText("COM port");
comPortColumn.getColumn().setWidth(COLUMN_WIDTH_NARROW);

comPortColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject p = (MoxaModelObject) element;
return p.getComPort();
}
});
}

/**
* @param viewer
*/
private void makePhysicalPortColumn(final TreeViewer viewer) {
TreeViewerColumn moxaPortColumn = new TreeViewerColumn(viewer, SWT.NONE);
moxaPortColumn.getColumn().setText("Physical MOXA port");
moxaPortColumn.getColumn().setWidth(COLUMN_WIDTH);

moxaPortColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof MoxaList) {
MoxaList list = MoxaList.class.cast(element);
String name = list.name;

// extracting uptime for conversion and display
String[] parts = name.split("\\)\\(");
if (1 < parts.length) {
String uptime = parts[1].substring(0, parts[1].length() - 1);
name = parts[0] + ") [Up " + MoxasViewModel.toDaysHoursMinutes(Long.valueOf(uptime) * 10) + "]";
}
return name;
} else {
MoxaModelObject p = (MoxaModelObject) element;
return p.getPhysPort();
}
}
});
}

/**
* @param viewer
*/
private void makeConnectedIOCColumn(final TreeViewer viewer) {
TreeViewerColumn iocColumn = new TreeViewerColumn(viewer, SWT.NONE);
iocColumn.getColumn().setText("Connected IOC");
iocColumn.getColumn().setWidth(COLUMN_WIDTH_NARROW);

iocColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Color getForeground(Object element) {
// Change the text colour of cells where a port is connected to multiple IOCs
if (element instanceof MoxaModelObject) {
MoxaModelObject p = (MoxaModelObject) element;
List<Ioc> iocs = p.getIocs();

if (iocs.size() > 1) {
return new Color(255, 0, 0);
}
}
return super.getForeground(element);
}

@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject p = (MoxaModelObject) element;
List<Ioc> iocs = p.getIocs();

return iocs.stream().map(Ioc::getName).collect(joining(", "));
}
});
}

/**
* @param viewer
*/
private void makeStatusColumn(final TreeViewer viewer) {
TreeViewerColumn infoColumn = new TreeViewerColumn(viewer, SWT.NONE);
infoColumn.getColumn().setText("Status");
infoColumn.getColumn().setWidth(COLUMN_WIDTH_NARROW);

infoColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject field = (MoxaModelObject) element;
return field.getStatus();
}

@Override
public Color getForeground(Object element) {
// Change the text colour of cells where a port is physically connected
if (element instanceof MoxaModelObject) {
MoxaModelObject field = (MoxaModelObject) element;

if (field.getStatus().equalsIgnoreCase(UP_STATUS)) {
return new Color(0, 0, 255);
}
}
return super.getForeground(element);
}
});
}

/**
* @param viewer
*/
private void makeAdditionInfoColumn(final TreeViewer viewer) {
TreeViewerColumn infoColumn = new TreeViewerColumn(viewer, SWT.NONE);
infoColumn.getColumn().setText("Additional Info");
infoColumn.getColumn().setWidth(COLUMN_WIDTH);

infoColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ArrayList<?>) {
return null;
}
MoxaModelObject field = (MoxaModelObject) element;
return field.getAdditionalInfo();
}
});
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* This file is part of the ISIS IBEX application. Copyright (C) 2012-2015
* This file is part of the ISIS IBEX application. Copyright (C) 2012-2023
* Science & Technology Facilities Council. All rights reserved.
*
* This program is distributed in the hope that it will be useful. This program
Expand Down Expand Up @@ -44,18 +44,24 @@ public class MoxaModelObject extends ModelObject implements Comparable<MoxaModel
private final String physport;
private final String comport;
private final List<Ioc> iocs;
private final String status;
private final String additionalInfo;

/**
* Instantiates a new moxa mapping pair.
*
* @param physport physical moxa port number for a mapping.
* @param comport COM port for a mapping.
* @param iocs List of IOCs using the COM port.
* @param status the Operation Status information
* @param additionalInfo Any additional information available for the port
*/
public MoxaModelObject(String physport, String comport, List<Ioc> iocs) {
public MoxaModelObject(String physport, String comport, List<Ioc> iocs, String status, String additionalInfo) {
this.physport = physport;
this.comport = comport;
this.iocs = new ArrayList<Ioc>(iocs);
this.additionalInfo = additionalInfo;
this.status = status;
}

/**
Expand Down Expand Up @@ -83,6 +89,21 @@ public String getComPort() {
public List<Ioc> getIocs() {
return new ArrayList<Ioc>(iocs);
}

/**
* @return status of the port
*/
public String getStatus() {
return status;
}

/**
*
* @return any additional information
*/
public String getAdditionalInfo() {
return additionalInfo;
}

/**
* {@inheritDoc}
Expand Down
Loading

0 comments on commit 398d64f

Please sign in to comment.