Thanks for your response.
Thatâs the thing I tried but did not work. Eclipse returns the error message:
Preformatted textThe method getInstallationAPI() is undefined for the type ViewAPIProvider
Eclipse then suggests to
Add cast to âapiProviderâ
which of course does not work. Maybe I did a failure elsewhere but I am not able to find it.
I just commented everything not needed and modified my code so that eclipse will let me run it. You might see that ioModel is always null, so my code wont work as intended:
View Class:
package com.ruhrboticsGmbH.ProfinetMonitor.impl;
import java.awt.*;
import javax.swing.*;
import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
import com.ur.urcap.api.contribution.ViewAPIProvider;
import com.ur.urcap.api.domain.io.DigitalIO;
import com.ur.urcap.api.domain.io.IOModel;
public class ProfinetMonitorInstallationNodeView implements SwingInstallationNodeView<ProfinetMonitorInstallationNodeContribution> {
private final ViewAPIProvider apiProvider;
private final JTabbedPane tabbedPane = new JTabbedPane();
private IOHelper ioHelper = null;
private final IOModel ioModel;
private DigitalIO[] digitalOutputs;
private String[] digitalOutputNames;
public ProfinetMonitorInstallationNodeView(ViewAPIProvider apiProvider, IOModel ioModel) {
this.apiProvider = apiProvider;
this.ioModel = ioModel;
this.ioHelper = ioHelper;
}
@Override
public void buildUI(JPanel panel, ProfinetMonitorInstallationNodeContribution contribution) {
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
tabbedPane.addTab("Digital", createPanelDigital());
panel.add(tabbedPane);
}
private JPanel createPanelDigital() {
JPanel[] inputOutputPanels = createInputOutputPanels();
JScrollPane scrollPaneInputs = createDigitalOutputScrollPane();
JScrollPane scrollPaneOutputs = createDigitalOutputScrollPane();
addInputOutputComponents(inputOutputPanels, scrollPaneInputs, scrollPaneOutputs);
return createMainPanelStructure(inputOutputPanels);
}
private void addInputOutputComponents(JPanel[] inputOutputPanels, JScrollPane scrollPaneInputs, JScrollPane scrollPaneOutputs) {
Box boxInputsHeadline = createLabeledBox(new JLabel(" Inputs"));
Box boxInputs = createBoxWithComponent(scrollPaneInputs);
Box boxOutputsHeadline = createLabeledBox(new JLabel(" Outputs"));
Box boxOutputs = createBoxWithComponent(scrollPaneOutputs);
inputOutputPanels[0].add(boxInputsHeadline);
inputOutputPanels[0].add(boxInputs);
inputOutputPanels[1].add(boxOutputsHeadline);
inputOutputPanels[1].add(boxOutputs);
}
private JPanel createMainPanelStructure(JPanel[] inputOutputPanels) {
JPanel primaryPanel = new JPanel(new BorderLayout());
JPanel secondaryCenterPanel = new JPanel();
secondaryCenterPanel.setLayout(new BoxLayout(secondaryCenterPanel, BoxLayout.LINE_AXIS));
secondaryCenterPanel.add(inputOutputPanels[0]);
secondaryCenterPanel.add(inputOutputPanels[1]);
primaryPanel.add(secondaryCenterPanel, BorderLayout.CENTER);
primaryPanel.add(createImagePanel(), BorderLayout.SOUTH);
return primaryPanel;
}
private JPanel[] createInputOutputPanels() {
JPanel panelS1 = new JPanel();
panelS1.setLayout(new BoxLayout(panelS1, BoxLayout.PAGE_AXIS));
panelS1.setBorder(BorderFactory.createLineBorder(Color.decode("#45494C")));
panelS1.setBackground(Color.decode("#FF9E1B"));
JPanel panelS2 = new JPanel();
panelS2.setLayout(new BoxLayout(panelS2, BoxLayout.PAGE_AXIS));
panelS2.setBorder(BorderFactory.createLineBorder(Color.decode("#45494C")));
panelS2.setBackground(Color.decode("#FF9E1B"));
return new JPanel[]{panelS1, panelS2};
}
private JScrollPane createDigitalOutputScrollPane() {
digitalOutputs = new DigitalIO[8];
digitalOutputNames = new String[8];
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
for (int i = 0; i < 8; i++) {
if (digitalOutputs[i] != null) {
digitalOutputNames[i] = digitalOutputs[i].getName();
}
else {
digitalOutputNames[i] = "Output " + i;
}
JLabel label = new JLabel(digitalOutputNames[i]);
panel.add(label);
}
JScrollPane OutputList = new JScrollPane(panel);
return OutputList;
}
private Box createLabeledBox(JLabel label) {
label.setFont(new Font("SansSerif", Font.BOLD, 18));
Box box = Box.createHorizontalBox();
box.add(label);
return box;
}
private Box createBoxWithComponent(Component component) {
Box box = Box.createHorizontalBox();
box.add(component);
return box;
}
private JPanel createImagePanel() {
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new BoxLayout(imagePanel, BoxLayout.X_AXIS));
ImageIcon logoIcon = new ImageIcon(getClass().getResource("/icons/ruhrbotics_logo_lang.png"));
JLabel logoLabel = new JLabel(logoIcon);
imagePanel.add(Box.createHorizontalGlue());
imagePanel.add(logoLabel);
return imagePanel;
}
}
Contribution Class:
package com.ruhrboticsGmbH.ProfinetMonitor.impl;
import com.ur.urcap.api.contribution.InstallationNodeContribution;
import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
import com.ur.urcap.api.domain.data.DataModel;
import com.ur.urcap.api.domain.script.ScriptWriter;
import com.ur.urcap.api.domain.io.IOModel;
public class ProfinetMonitorInstallationNodeContribution implements InstallationNodeContribution {
private final InstallationAPIProvider apiProvider;
private final ProfinetMonitorInstallationNodeView view;
private final DataModel model;
private final IOHelper ioHelper;
public ProfinetMonitorInstallationNodeContribution(InstallationAPIProvider apiProvider, IOModel ioModel, ProfinetMonitorInstallationNodeView view,
DataModel model) {
this.apiProvider = apiProvider;
this.view = view;
this.ioHelper = new IOHelper(ioModel);
this.model = model;
}
@Override
public void openView() {
// TODO Auto-generated method stub
}
@Override
public void closeView() {
// TODO Auto-generated method stub
}
@Override
public void generateScript(ScriptWriter writer) {
// TODO Auto-generated method stub
}
}
Service Class:
package com.ruhrboticsGmbH.ProfinetMonitor.impl;
import java.util.Locale;
import com.ur.urcap.api.contribution.ViewAPIProvider;
import com.ur.urcap.api.contribution.installation.ContributionConfiguration;
import com.ur.urcap.api.contribution.installation.CreationContext;
import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService;
import com.ur.urcap.api.domain.data.DataModel;
import com.ur.urcap.api.domain.io.IOModel;
public class ProfinetMonitorInstallationNodeService implements SwingInstallationNodeService<ProfinetMonitorInstallationNodeContribution, ProfinetMonitorInstallationNodeView>{
@Override
public void configureContribution(ContributionConfiguration configuration) {
}
@Override
public String getTitle(Locale locale) {
return "Profinet";
}
@Override
public ProfinetMonitorInstallationNodeView createView(ViewAPIProvider apiProvider) {
IOModel ioModel = null;
return new ProfinetMonitorInstallationNodeView(apiProvider, ioModel);
}
@Override
public ProfinetMonitorInstallationNodeContribution createInstallationNode(InstallationAPIProvider apiProvider,
ProfinetMonitorInstallationNodeView view, DataModel model, CreationContext context) {
IOModel ioModel = null;
return new ProfinetMonitorInstallationNodeContribution(apiProvider, ioModel, view, model);
}
}
When I change everything to how I think it should work my view class looks like this: