Added support for plugins

This commit is contained in:
2014-12-05 17:44:40 +01:00
commit e2cc7e1fd8
6 changed files with 457 additions and 0 deletions

52
nbactions.xml Normal file
View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>../pshell</exec.workingdir>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
<exec.workingdir>../pshell</exec.workingdir>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>../pshell</exec.workingdir>
</properties>
</action>
</actions>

20
pom.xml Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.psi</groupId>
<artifactId>plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pshell</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>

16
pshell.properties Normal file
View File

@@ -0,0 +1,16 @@
#Thu Dec 04 18:06:51 CET 2014
dataPath={home}/data
logPath={home}/log
logLevel=Info
libraryPath={script}; {script}/site-packages
scriptPath={home}/script
serverPort=-1
contextPath={home}/context
logDaysToLive=-1
devicePoolFile={devices}/devices.properties
homePath=./home
deviceUpdateStrategyFile={devices}/update.properties
devicesPath={home}/devices
test=false
sessionsPath={home}/sessions
scriptType=py

View File

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="motorPanel1" min="-2" max="-2" attributes="0"/>
<Component id="motorPanel2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="82" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel1" pref="0" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="motorPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="motorPanel2" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="30" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="ch.psi.pshell.swing.MotorPanel" name="motorPanel1">
<Properties>
<Property name="showTitle" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="ch.psi.pshell.swing.MotorPanel" name="motorPanel2">
<Properties>
<Property name="showTitle" type="boolean" value="true"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Tasks"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="2" attributes="0">
<Component id="buttonStart1" alignment="2" pref="193" max="32767" attributes="0"/>
<Component id="buttonStart2" alignment="2" pref="193" max="32767" attributes="0"/>
<Component id="buttonStart3" alignment="2" pref="193" max="32767" attributes="0"/>
<Component id="buttonStart4" alignment="2" pref="193" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="buttonStart1" linkSize="1" min="-2" pref="32" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="buttonStart2" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="buttonStart3" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="buttonStart4" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="95" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="buttonStart1">
<Properties>
<Property name="text" type="java.lang.String" value="Start Data Acquisition 1"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonStart2">
<Properties>
<Property name="text" type="java.lang.String" value="Start Data Acquisition 2"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart2ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonStart3">
<Properties>
<Property name="text" type="java.lang.String" value="Start Data Acquisition 3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart3ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonStart4">
<Properties>
<Property name="text" type="java.lang.String" value="Start Data Acquisition 4"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart4ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -0,0 +1,209 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.core.Controller;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.View;
import ch.psi.utils.State;
import ch.psi.utils.Swing;
import ch.psi.wsaf.ApplicationStateAdapter;
import ch.psi.wsaf.ApplicationStateListener;
/**
*
*/
public class MainPanel extends javax.swing.JPanel {
final App app;
final View view;
final Controller controller;
/**
* Creates new form MainPanel
*/
public MainPanel() {
initComponents();
app=App.getInstance();
controller=app.getController();
view=(View) app.getMainFrame();
app.addStateListener(applicationStateListener);
}
ApplicationStateListener applicationStateListener = new ApplicationStateAdapter() {
@Override
public void onChangedState(State newState, State curState) {
try{
if (newState==State.Ready){
motorPanel1.setDevice(controller.getDevicePool().getByName("motor"));
motorPanel2.setDevice(controller.getDevicePool().getByName("m"));
}else{
if (!newState.isInitialized()){
motorPanel1.setDevice(null);
motorPanel2.setDevice(null);
}
}
buttonStart1.setEnabled(newState==State.Ready);
buttonStart2.setEnabled(newState==State.Ready);
buttonStart3.setEnabled(newState==State.Ready);
buttonStart4.setEnabled(newState==State.Ready);
motorPanel1.setEnabled(newState==State.Ready);
motorPanel2.setEnabled(newState==State.Ready);
}
catch (Exception ex){
ex.printStackTrace();
}
}
};
void runScript(final String name){
new Thread(new Runnable() {
@Override
public void run() {
try{
controller.evalFile(name, true);
}catch (Exception ex){
Swing.showException(view, ex);
}
}
}).start();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
motorPanel1 = new ch.psi.pshell.swing.MotorPanel();
motorPanel2 = new ch.psi.pshell.swing.MotorPanel();
jPanel1 = new javax.swing.JPanel();
buttonStart1 = new javax.swing.JButton();
buttonStart2 = new javax.swing.JButton();
buttonStart3 = new javax.swing.JButton();
buttonStart4 = new javax.swing.JButton();
motorPanel1.setShowTitle(true);
motorPanel2.setShowTitle(true);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tasks"));
buttonStart1.setText("Start Data Acquisition 1");
buttonStart1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStart1ActionPerformed(evt);
}
});
buttonStart2.setText("Start Data Acquisition 2");
buttonStart2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStart2ActionPerformed(evt);
}
});
buttonStart3.setText("Start Data Acquisition 3");
buttonStart3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStart3ActionPerformed(evt);
}
});
buttonStart4.setText("Start Data Acquisition 4");
buttonStart4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStart4ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonStart1, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
.addComponent(buttonStart2, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
.addComponent(buttonStart3, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
.addComponent(buttonStart4, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(buttonStart2)
.addGap(18, 18, 18)
.addComponent(buttonStart3)
.addGap(18, 18, 18)
.addComponent(buttonStart4)
.addGap(95, 95, 95))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonStart1, buttonStart2, buttonStart3, buttonStart4});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(82, 82, 82))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(motorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(30, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void buttonStart1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart1ActionPerformed
// TODO add your handling code here:
runScript("test1");
}//GEN-LAST:event_buttonStart1ActionPerformed
private void buttonStart2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart2ActionPerformed
// TODO add your handling code here:
runScript("test2");
}//GEN-LAST:event_buttonStart2ActionPerformed
private void buttonStart3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart3ActionPerformed
// TODO add your handling code here:
runScript("test3");
}//GEN-LAST:event_buttonStart3ActionPerformed
private void buttonStart4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart4ActionPerformed
// TODO add your handling code here:
runScript("test4");
}//GEN-LAST:event_buttonStart4ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonStart1;
private javax.swing.JButton buttonStart2;
private javax.swing.JButton buttonStart3;
private javax.swing.JButton buttonStart4;
private javax.swing.JPanel jPanel1;
private ch.psi.pshell.swing.MotorPanel motorPanel1;
private ch.psi.pshell.swing.MotorPanel motorPanel2;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.ui.Plugin;
/**
*
*/
public class TestPlugin extends Plugin{
MainPanel panel;
@Override
protected void onStart() {
panel = new MainPanel();
getView().getDocumentsTab().insertTab("Main",null,panel,null,0);
getView().getDocumentsTab().setSelectedComponent(panel);
}
@Override
protected void onStop() {
}
}