📄 newflowcreationwizardpage.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.ui.wizards;
import java.io.InputStream;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.ui.Flow4jPluginImages;
import net.orthanc.flow4j.model.bind.BindingHandler;
import net.orthanc.flow4j.model.bind.FlowModelBind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
/**
* @author agreif
*
* TODO
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NewFlowCreationWizardPage extends WizardNewFileCreationPage {
private IPath newFilePath;
/**
* TODO
* @param pageName
* @param selection
*/
public NewFlowCreationWizardPage(IStructuredSelection selection) {
super(Flow4JPlugin.getResourceString("WizardPage_NewFlow.pageName"), selection); //$NON-NLS-1$
setDescription(Flow4JPlugin.getResourceString("WizardPage_NewFlow.pageDescription")); //$NON-NLS-1$
setImageDescriptor(Flow4jPluginImages.DESC_WIZBAN_NEWFLOW);
}
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
super.createControl(parent);
this.setFileName(Flow4JPlugin.getResourceString("WizardPage_NewFlow.fileName")); //$NON-NLS-1$
this.setPageComplete(this.validatePage());
}
/**
* @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#createFileHandle(org.eclipse.core.runtime.IPath)
*/
protected IFile createFileHandle(IPath filePath) {
newFilePath = filePath;
return super.createFileHandle(filePath);
}
/**
* Returns the Input straeam to the serialized content of a new FlowModelBind object.
* Sets the default flow name to the flowFile name without the extension
* @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#getInitialContents()
*/
protected InputStream getInitialContents() {
try {
String fileName = newFilePath.lastSegment();
String flowName = fileName.substring(0, fileName.length()-newFilePath.getFileExtension().length()-1);
FlowModelBind flowModelBind = new FlowModelBind(flowName);
return BindingHandler.getInstance().saveFlowModel(flowModelBind);
} catch (Exception e) {
Flow4JPlugin.log(e);
return null;
}
}
/**
* TODO
* @return
*/
boolean finish() {
IFile newFile = this.createNewFile();
if (newFile == null)
return false; // ie.- creation was unsuccessful
// Since the flowFile resource was created fine, open it for editing
// if requested by the user
try {
IWorkbenchWindow dwindow = Flow4JPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
if (dwindow != null) {
IWorkbenchPage page = dwindow.getActivePage();
if (page != null)
page.openEditor(newFile);
}
} catch (org.eclipse.ui.PartInitException e) {
Flow4JPlugin.log(e);
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -