📄 javataskflowlettooltipfigure.java
字号:
/*
* Copyright (c) 2003, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.designer.figures;
import java.util.Iterator;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.editparts.IFlow4JToolTip;
import net.orthanc.flow4j.designer.editparts.JavaTaskFlowletEditPart;
import net.orthanc.flow4j.designer.model.JavaTaskFlowletModelPart;
import net.orthanc.flow4j.runtime.ITaskFlowlet;
import net.orthanc.flow4j.runtime.descriptors.TaskParameterDescriptor;
import net.orthanc.flow4j.runtime.descriptors.TaskParameterDescriptors;
import net.orthanc.flow4j.runtime.descriptors.TaskPropertyDescriptor;
import net.orthanc.flow4j.runtime.descriptors.TaskPropertyDescriptors;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Panel;
/**
* Tool tip figure of the task flowlet.
* @author alex
*/
public class JavaTaskFlowletToolTipFigure extends Panel implements IFlow4JToolTip {
static public String TOOLTIP_PROP_CLASSNAME =
"tooltip_taskflowlet_classname";
static public String TOOLTIP_PROP_DESCRIPTION =
"tooltip_taskflowlet_description";
private String className = "";
private String description = "";
private Label classNameLabel = new Label();
private Label descriptionLabel = new Label();
private Panel propertiesPanel;
private Panel parametersPanel;
private JavaTaskFlowletEditPart taskFlowletEditPart;
/**
* Constructor. Creates all the panels and sets the layout
*/
public JavaTaskFlowletToolTipFigure(JavaTaskFlowletEditPart taskFlowletEditPart) {
super();
this.taskFlowletEditPart = taskFlowletEditPart;
Panel classNamePanel = new Panel();
classNamePanel.add(classNameLabel);
classNamePanel.setLayoutManager(new FlowLayout(false));
add(classNamePanel);
Panel descriptionPanel = new Panel();
descriptionPanel.add(descriptionLabel);
descriptionPanel.setLayoutManager(new FlowLayout(false));
add(descriptionPanel);
propertiesPanel = new Panel();
FlowLayout lay1 = new FlowLayout(false);
lay1.setMinorSpacing(0);
propertiesPanel.setLayoutManager(lay1);
add(propertiesPanel);
parametersPanel = new Panel();
FlowLayout lay2 = new FlowLayout(false);
lay2.setMinorSpacing(0);
parametersPanel.setLayoutManager(lay2);
add(parametersPanel);
FlowLayout lay3 = new FlowLayout(false);
lay3.setMinorSpacing(0);
setLayoutManager(lay3);
}
/**
* Updates the given value of the tooltip
* @see net.orthanc.flow4j.designer.editparts.IFlow4JToolTip#update(java.lang.String, java.lang.Object)
*/
public void update(String key, Object value) {
if (TOOLTIP_PROP_CLASSNAME.equals(key)) {
className = (String) value;
classNameLabel.setText("class: " + className);
} else if (TOOLTIP_PROP_DESCRIPTION.equals(key)) {
description = (String) value;
descriptionLabel.setText("desc: " + description);
}
}
/**
* Updates the tooltip's contents and repaints the figure.
* @see org.eclipse.draw2d.IFigure#repaint()
*/
public void repaint() {
updateContents();
super.repaint();
}
/**
* Updates the tollbox's contents.
* Gets the description form the task class.
*
*/
private void updateContents() {
JavaTaskFlowletModelPart taskFlowletModelPart =
(JavaTaskFlowletModelPart) taskFlowletEditPart.getModel();
propertiesPanel.removeAll();
parametersPanel.removeAll();
// update description
String description;
try {
ITaskFlowlet taskFlowletInstance =
taskFlowletModelPart.getTaskFlowletInstance(className);
description = taskFlowletInstance.getDescription();
// update properties
updateProperties(taskFlowletInstance, taskFlowletModelPart);
// update parameters
updateParameters(taskFlowletInstance);
} catch (ClassNotFoundException e) {
description = "N/A";
} catch (Throwable e) {
Flow4JPlugin.log(e);
description = "N/A";
}
update(
JavaTaskFlowletToolTipFigure.TOOLTIP_PROP_DESCRIPTION,
description == null ? "" : description);
}
/**
* Updates the properties
* @param taskFlowletInstance
* @param taskFlowletModelPart
*/
private void updateProperties(
ITaskFlowlet taskFlowletInstance,
JavaTaskFlowletModelPart taskFlowletModelPart) {
TaskPropertyDescriptors taskPropDescs =
taskFlowletInstance.getPropertyDescriptors();
if (taskPropDescs == null || taskPropDescs.isEmpty())
return;
Label label = new Label("Properties:");
label.setFont(FigureUtils.getBold(propertiesPanel.getFont()));
propertiesPanel.add(label);
for (Iterator iter = taskPropDescs.iterator(); iter.hasNext();) {
TaskPropertyDescriptor taskPropDesc =
(TaskPropertyDescriptor) iter.next();
String propValue = taskFlowletModelPart.getTaskProperty(
taskPropDesc.getName());
propValue = propValue == null ? "" : propValue;
propertiesPanel.add(
new Label(taskPropDesc.getName() + " = " + propValue));
}
}
/**
* Updates the parameters.
* @param taskFlowletInstance
*/
private void updateParameters(ITaskFlowlet taskFlowletInstance) {
TaskParameterDescriptors taskInParamDescs =
taskFlowletInstance.getInputParameterDescriptors();
TaskParameterDescriptors taskOutParamDescs =
taskFlowletInstance.getOutputParameterDescriptors();
if ((taskInParamDescs == null || taskInParamDescs.isEmpty())
&& (taskOutParamDescs == null || taskOutParamDescs.isEmpty()))
return;
if (taskInParamDescs != null && ! taskInParamDescs.isEmpty()) {
Label label = new Label("Input parameters:");
label.setFont(FigureUtils.getBold(parametersPanel.getFont()));
parametersPanel.add(label);
printParameters(taskFlowletInstance.getInputParameterDescriptors());
}
if (taskOutParamDescs != null && ! taskOutParamDescs.isEmpty()) {
Label label = new Label("Output parameters:");
label.setFont(FigureUtils.getBold(parametersPanel.getFont()));
parametersPanel.add(label);
printParameters(taskFlowletInstance.getOutputParameterDescriptors());
}
}
/**
* Prints the parameters in the tooltip.
* @param taskParamDescs
*/
private void printParameters(TaskParameterDescriptors taskParamDescs) {
for (Iterator iter = taskParamDescs.iterator(); iter.hasNext();) {
TaskParameterDescriptor taskParamDesc =
(TaskParameterDescriptor) iter.next();
String type = taskParamDesc.getType() == null ? "N/A" : taskParamDesc.getType();
parametersPanel.add(
new Label(taskParamDesc.getName() + " - " + type));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -