⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportentrieswizardpage.java

📁 基于Eclipse RCP开发的管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 /*    * Copyright 2006 Marcel Schoffelmeer   *   * Licensed under the Apache License, Version 2.0 (the "License");   * you may not use this file except in compliance with the License.   * You may obtain a copy of the License at   *   *    http://www.apache.org/licenses/LICENSE-2.0   *      * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */package com.s10r.manager.exinport;import java.io.File;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import org.eclipse.core.runtime.Path;import org.eclipse.jface.dialogs.IDialogConstants;import org.eclipse.jface.dialogs.IDialogSettings;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.wizard.WizardPage;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Combo;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Widget;import org.eclipse.ui.IEditorPart;import org.eclipse.ui.IWorkbench;import org.eclipse.ui.dialogs.IOverwriteQuery;import com.s10r.manager.EntryEditor;// This class is derived from the Eclipse SDK source. See preferences import/export classes// at:// eclipse/src/plugins///     org.eclipse.ui.workbench/Eclipse UI///          org/eclipse/ui/internal/wizards/preferencespublic class ExportEntriesWizardPage extends WizardPage implements Listener,		IOverwriteQuery{	protected Combo destinationNameField;	// constants	private Button destinationBrowseButton;	private Button overwriteExistingFilesCheckbox;	protected static final int COMBO_HISTORY_LENGTH = 5;	private static final String STORE_DESTINATION_NAMES_ID = "ExportEntriesWizardPage.STORE_DESTINATION_NAMES_ID";//$NON-NLS-1$	private static final String STORE_OVERWRITE_EXISTING_FILES_ID = "ExportEntriesWizardPage.STORE_OVERWRITE_EXISTING_FILES_ID";	private static final String ENTRIES_EXPORT_PAGE = "entriesexportpage";	private static final String STORE_DESTINATION_ID = null;	private String currentMessage;	private Combo transferEditorField;	private IWorkbench workbench;	private IEditorPart activeEditor;	protected void addDestinationItem(String value)	{		destinationNameField.add(value);	}	protected ExportEntriesWizardPage(IWorkbench workbench)	{		super(ENTRIES_EXPORT_PAGE);		setTitle("Export password entries");		setDescription("Export the password entries to the local file system in XML format. "				+ "Warning: the passwords will be stored in plain text (e.g. non-encrypted).");		this.workbench = workbench;	}	public void createControl(Composite parent)	{		// TODO Auto-generated method stub		initializeDialogUnits(parent);		Font wizardFont = parent.getFont();		Composite composite = new Composite(parent, SWT.NULL);		composite.setLayout(new GridLayout());		composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL				| GridData.HORIZONTAL_ALIGN_FILL));		composite.setFont(wizardFont);		createTransferArea(composite);		restoreWidgetValues();		// can not finish initially, but don't want to start with an error		// message either		if (!validateDestinationGroup())		{			setPageComplete(false);		}		// setPreferenceTransfers();		setControl(composite);		giveFocusToDestination();	}	private boolean validateDestinationGroup()	{		if (!validDestination())		{			currentMessage = getInvalidDestinationMessage();			return false;		}		return true;	}	private boolean validDestination()	{		File file = new File(getDestinationValue());		return !(file.getPath().length() <= 0 || file.isDirectory());	}	private String getInvalidDestinationMessage()	{		// TODO Auto-generated method stub		return "Choose a valid destination file to write to";	}	private void giveFocusToDestination()	{		destinationNameField.setFocus();	}	protected void createTransferArea(Composite composite)	{		createTransfersList(composite);		createDestinationGroup(composite);		createOptionsGroup(composite);	}	private void createTransfersList(Composite parent)	{		Font parentFont = parent.getFont();		Composite transferSelectionGroup = new Composite(parent, SWT.NONE);		GridLayout layout = new GridLayout();		layout.numColumns = 3;		transferSelectionGroup.setLayout(layout);		transferSelectionGroup.setLayoutData(new GridData(				GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));		transferSelectionGroup.setFont(parentFont);		Label dest = new Label(transferSelectionGroup, SWT.NONE);		dest.setText("Select editor content to export:");		dest.setFont(parentFont);		// destination name entry field		transferEditorField = new Combo(transferSelectionGroup, SWT.SINGLE				| SWT.BORDER);		activeEditor = workbench.getActiveWorkbenchWindow().getActivePage()				.getActiveEditor();		if (activeEditor != null)		{			transferEditorField.add(activeEditor.getTitle(), 0);			transferEditorField.select(0);		}		transferEditorField.addListener(SWT.Modify, this);		transferEditorField.addListener(SWT.Selection, this);		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL				| GridData.GRAB_HORIZONTAL);		transferEditorField.setLayoutData(data);		transferEditorField.setFont(parentFont);		/*		 * IEditorReference[] editorsRefs =		 * workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();		 * for (IEditorReference editorRef : editorsRefs ) {		 * transferEditorField.add(editorRef.getTitle()); }		 */	}	protected void createDestinationGroup(Composite parent)	{		// destination specification group		Font parentFont = parent.getFont();		Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);		GridLayout layout = new GridLayout();		layout.numColumns = 3;		destinationSelectionGroup.setLayout(layout);		destinationSelectionGroup.setLayoutData(new GridData(				GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));		destinationSelectionGroup.setFont(parentFont);		Label dest = new Label(destinationSelectionGroup, SWT.NONE);		dest.setText("To password file:");		dest.setFont(parentFont);		// destination name entry field		destinationNameField = new Combo(destinationSelectionGroup, SWT.SINGLE				| SWT.BORDER);		destinationNameField.addListener(SWT.Modify, this);		destinationNameField.addListener(SWT.Selection, this);		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL				| GridData.GRAB_HORIZONTAL);		destinationNameField.setLayoutData(data);		destinationNameField.setFont(parentFont);		// destination browse button		destinationBrowseButton = new Button(destinationSelectionGroup,				SWT.PUSH);		destinationBrowseButton.setText("Browse...");		destinationBrowseButton.setLayoutData(new GridData(				GridData.HORIZONTAL_ALIGN_FILL));		destinationBrowseButton.addListener(SWT.Selection, this);		destinationBrowseButton.setFont(parentFont);		new Label(parent, SWT.NONE); // vertical spacer	}	public void handleEvent(Event e)	{		Widget source = e.widget;		if (source == destinationBrowseButton)		{			handleDestinationBrowseButtonPressed();		}		updatePageCompletion();	}	private void updatePageCompletion()	{		boolean pageComplete = determinePageCompletion();		setPageComplete(pageComplete);		if (pageComplete)		{			setMessage(null);		}	}	private boolean determinePageCompletion()	{		boolean complete = validateDestinationGroup();		// Avoid draw flicker by not clearing the error		// message unless all is valid.		if (complete)		{			setErrorMessage(null);		}		else		{			setErrorMessage(currentMessage);		}		return complete;	}	private void handleDestinationBrowseButtonPressed()	{		System.out.println("handleDestinationBrowseButtonPressed");		FileDialog dialog = new FileDialog(getContainer().getShell(),				getFileDialogStyle());		dialog.setText("Select file");		dialog.setFilterPath(getDestinationValue());		dialog.setFilterNames(new String[] { "XML Files", "All files" });				dialog.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -