📄 javataskflowleteditpart.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.editparts;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.editparts.policies.TaskFlowletDirectEditPolicy;
import net.orthanc.flow4j.designer.figures.Flow4FigureFactory;
import net.orthanc.flow4j.designer.figures.JavaTaskFlowletFigure;
import net.orthanc.flow4j.designer.figures.JavaTaskFlowletToolTipFigure;
import net.orthanc.flow4j.designer.model.JavaTaskFlowletModelPart;
import net.orthanc.flow4j.designer.ui.editors.JarEntryEditorInput;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.ITypeNameRequestor;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
/**
* Edit part of a java task flowlet.
* @author agreif
*/
public class JavaTaskFlowletEditPart extends FlowletWithLabelEditPart
{
/**
* The toolTip figure that will be reused for flowlet figure creation.
*/
private JavaTaskFlowletToolTipFigure toolTip;
/**
* Constructor.
* Sets the tooltip.
*/
public JavaTaskFlowletEditPart() {
super();
toolTip = new JavaTaskFlowletToolTipFigure(this);
}
/**
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
*/
protected void createEditPolicies() {
super.createEditPolicies();
installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new TaskFlowletDirectEditPolicy());
}
/**
* Creates the task flowlet figure and sets it's tool tip figure
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
*/
protected IFigure createFigure() {
if (getModel() == null)
return null;
IFigure figure = Flow4FigureFactory.createJavaTaskFlowletFigure();
figure.setToolTip(toolTip);
return figure;
}
/**
* Returns the Figure for this as an OutputFigure.
* @return Figure of this as a OutputFigure.
*/
protected JavaTaskFlowletFigure getJavaTaskFlowletFigure() {
return (JavaTaskFlowletFigure)getFigure();
}
/**
* Returns the model of this as a JavaTaskFlowletModelPart.
* @return Model of this as a JavaTaskFlowletModelPart.
*/
protected JavaTaskFlowletModelPart getJavaTaskFlowlet() {
return (JavaTaskFlowletModelPart)getModel();
}
/**
* Performs a direct edit on the Task Flowlet.
* Searches for the class's java source and opens it.
* If the java source is in a jar or zip archive,
* then its currently not handled.
*/
private void performDirectEdit() {
String className = getJavaTaskFlowlet().getFlowletLabel().getText();
try {
new SearchEngine()
.searchAllTypeNames(
Flow4JPlugin.getWorkspace(),
className.substring(0, className.lastIndexOf(".")).toCharArray(),
className.substring(className.lastIndexOf(".") + 1).toCharArray(),
IJavaSearchConstants.EXACT_MATCH,
true,
IJavaSearchConstants.CLASS,
SearchEngine.createWorkspaceScope(),
new ITypeNameRequestor() {
public void acceptClass(
char[] packageName,
char[] simpleTypeName,
char[][] enclosingTypeNames,
String pathStr) {
int jarSepPos = pathStr.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
IPath path = new Path(pathStr);
IWorkbenchPage page = Flow4JPlugin.getActivePage();
if (page != null)
try {
if (jarSepPos == -1) {
IPath projectLocation = Flow4JPlugin.getJavaProject(path.segment(0)).getProject().getLocation();
IPath location = projectLocation.append(path.removeFirstSegments(1));
IFile file = Flow4JPlugin.getWorkspaceRoot().getFileForLocation(location);
page.openEditor(file, Flow4JPlugin.getEditorID(pathStr), true);
/* Peter Friese */
// IEditorInput input = (IEditorInput) file.getAdapter(IEditorInput.class);
// page.openEditor(input, Flow4JPlugin.getEditorID(pathStr), true);
} else {
page.openEditor(new JarEntryEditorInput(pathStr), Flow4JPlugin.getEditorID(pathStr), true);
}
} catch (PartInitException e) {
Flow4JPlugin.log("Exception while opening task java source: " + e.getMessage());
//Flow4JPlugin.getActiveFlowEditor().getStatusLineManager().setErrorMessage("hallo");
}
}
public void acceptInterface(
char[] packageName,
char[] simpleTypeName,
char[][] enclosingTypeNames,
String path) {
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @see org.eclipse.gef.EditPart#performRequest(org.eclipse.gef.Request)
*/
public void performRequest(Request request) {
if (request.getType() == RequestConstants.REQ_DIRECT_EDIT)
performDirectEdit();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -