📄 flowexportwizardpage.java
字号:
/*
* Copyright (c) 2003-2004, 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.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
* Export wizard page which enables the project and destination folder
* selection.
* @author greifa
*/
public class FlowExportWizardPage extends WizardPage {
CheckboxTableViewer tableViewer;
Table table;
Text folderText;
Button browseButton;
List selectedProjects = new ArrayList();
String folder = ""; //$NON-NLS-1$
/**
* FlowExportWizardPage constructor comment.
* @param pageName the name of the page
* @param title the title of the page
* @param titleImage the image for the page
*/
public FlowExportWizardPage(
String pageName,
String title,
ImageDescriptor titleImage) {
super(pageName, title, titleImage);
}
public IProject[] getSelectedProjects() {
return (IProject[]) selectedProjects.toArray(
new IProject[selectedProjects.size()]);
}
public void setSelectedProjects(IProject[] selectedProjects) {
this.selectedProjects.addAll(Arrays.asList(selectedProjects));
}
public File getDestFolder() {
return new File(folder);
}
/**
* Called when the user presses the Cancel button. Return a boolean
* indicating permission to close the wizard.
*
* @return boolean
*/
public boolean cancel() {
return true;
}
/**
*
* @author greifa
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
class ProjectContentProvider extends WorkbenchContentProvider {
public Object[] getElements(Object element) {
if (element instanceof IProject[])
return (IProject[]) element;
return null;
}
};
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite composite = createComposite(parent, 1);
initializeDialogUnits(composite);
createLabel(composite, Flow4JPlugin.getResourceString("Wizard_FlowDoc.label.flow_projects")); //$NON-NLS-1$
table =
new Table(
composite,
SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer = new CheckboxTableViewer(table);
table.setLayout(new TableLayout());
GridData data = new GridData(GridData.FILL_BOTH);
data.heightHint = 300;
table.setLayoutData(data);
tableViewer.setContentProvider(new ProjectContentProvider());
tableViewer.setLabelProvider(new WorkbenchLabelProvider());
tableViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
IProject project = (IProject) event.getElement();
if (event.getChecked()) {
selectedProjects.add(project);
} else {
selectedProjects.remove(project);
}
updateEnablement();
}
});
createLabel(composite, Flow4JPlugin.getResourceString("Wizard_FlowDoc.label.export_dest")); //$NON-NLS-1$
Composite inner = new Composite(composite, SWT.NULL);
inner.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.numColumns = 3;
layout.marginHeight = 0;
layout.marginWidth = 0;
inner.setLayout(layout);
createLabel(inner, Flow4JPlugin.getResourceString("Wizard_FlowDoc.label.folder")); //$NON-NLS-1$
folderText = createTextField(inner);
if (folder != null)
folderText.setText(folder);
folderText.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
folder = folderText.getText();
updateEnablement();
}
});
browseButton = new Button(inner, SWT.PUSH);
browseButton.setText(Flow4JPlugin.getResourceString("Wizard_FlowDoc.button.browse")); //$NON-NLS-1$
data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.heightHint =
convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
int widthHint =
convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
data.widthHint =
Math.max(
widthHint,
browseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
browseButton.setLayoutData(data);
browseButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
//FileDialog d = new FileDialog(getShell(), SWT.SAVE);
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText(
Flow4JPlugin.getResourceString(
"Wizard_FlowDoc.dialog.title"));
dialog.setMessage(
Flow4JPlugin.getResourceString(
"Wizard_FlowDoc.dialog.message"));
String f = dialog.open();
if (f != null) {
File file = new File(f);
if (file.exists() && file.isDirectory())
folderText.setText(f);
folder = f;
}
}
});
initializeProjects();
setControl(composite);
updateEnablement();
}
private void initializeProjects() {
List projectList = new ArrayList();
IProject[] workspaceProjects =
ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i = 0; i < workspaceProjects.length; i++) {
if (Flow4JPlugin.hasFlow4JNature(workspaceProjects[i])) {
projectList.add(workspaceProjects[i]);
}
}
tableViewer.setInput(
(IProject[]) projectList.toArray(new IProject[projectList.size()]));
// Check any necessary projects
if (selectedProjects != null) {
tableViewer.setCheckedElements(
(IProject[]) selectedProjects.toArray(
new IProject[selectedProjects.size()]));
}
}
/**
* Creates composite control and sets the default layout data.
*
* @param parent the parent of the new composite
* @param numColumns the number of columns for the new composite
* @return the newly-created coposite
*/
protected Composite createComposite(Composite parent, int numColumns) {
Composite composite = new Composite(parent, SWT.NULL);
// GridLayout
GridLayout layout = new GridLayout();
layout.numColumns = numColumns;
composite.setLayout(layout);
// GridData
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
composite.setLayoutData(data);
return composite;
}
/**
* Utility method that creates a label instance
* and sets the default layout data.
*
* @param parent the parent for the new label
* @param text the text for the new label
* @return the new label
*/
protected Label createLabel(Composite parent, String text) {
return createIndentedLabel(parent, text, 0);
}
/**
* Checks user selections and input and sets the dialog message
* accordingly and also the button states.
*/
private void updateEnablement() {
boolean complete;
File file = getDestFolder();
if (selectedProjects.size() == 0) {
setMessage(null);
complete = false;
} else if (folder.length() == 0) {
setMessage(null);
complete = false;
} else if (!file.exists()) {
setMessage(Flow4JPlugin.getResourceString("Wizard_FlowDoc.dialog.message.folder_invalid")); //$NON-NLS-1$
complete = false;
} else {
if (file.isFile()) {
setMessage(Flow4JPlugin.getResourceString("Wizard_FlowDoc.label.specified_file"), ERROR); //$NON-NLS-1$
complete = false;
} else {
complete = true;
}
}
if (complete) {
setMessage(null);
}
setPageComplete(complete);
}
/**
* Create a text field specific for this application
*
* @param parent the parent of the new text field
* @return the new text field
*/
protected Text createTextField(Composite parent) {
Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.verticalAlignment = GridData.CENTER;
data.grabExcessVerticalSpace = false;
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
text.setLayoutData(data);
return text;
}
/**
* Utility method that creates a label instance indented by the specified
* number of pixels and sets the default layout data.
*
* @param parent the parent for the new label
* @param text the text for the new label
* @param indent the indent in pixels, or 0 for none
* @return the new label
*/
protected Label createIndentedLabel(
Composite parent,
String text,
int indent) {
Label label = new Label(parent, SWT.LEFT);
label.setText(text);
GridData data = new GridData();
data.horizontalSpan = 1;
data.horizontalAlignment = GridData.FILL;
data.horizontalIndent = indent;
label.setLayoutData(data);
return label;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -