📄 exportentrieswizardpage.java
字号:
String selectedFileName = dialog.open(); if (selectedFileName != null) { setDestinationValue(selectedFileName); } } protected String getOutputSuffix() { return ".xml"; //$NON-NLS-1$ } protected void setDestinationValue(String value) { destinationNameField.setText(value); } protected String getDestinationFieldValue() { return destinationNameField.getText().trim(); } protected String getDestinationValue() { String idealSuffix = getOutputSuffix(); String destinationText = getDestinationFieldValue(); // only append a suffix if the destination doesn't already have a . in // its last path segment. // Also prevent the user from selecting a directory. Allowing this will // create a ".epf" file in the directory if (destinationText.length() != 0 && !destinationText.endsWith(File.separator)) { int dotIndex = destinationText.lastIndexOf('.'); if (dotIndex != -1) { // the last path seperator index int pathSepIndex = destinationText.lastIndexOf(File.separator); if (pathSepIndex != -1 && dotIndex < pathSepIndex) { destinationText += idealSuffix; } } else { destinationText += idealSuffix; } } return destinationText; } private int getFileDialogStyle() { return SWT.SAVE; } protected void createOptionsGroup(Composite parent) { // options group Font parentFont = parent.getFont(); Composite optionsGroup = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; optionsGroup.setLayout(layout); optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); optionsGroup.setFont(parentFont); // overwrite... checkbox overwriteExistingFilesCheckbox = new Button(optionsGroup, SWT.CHECK | SWT.LEFT); overwriteExistingFilesCheckbox .setText("Overwrite existing files without warning"); overwriteExistingFilesCheckbox.setFont(parentFont); } public boolean finish() { // about to invoke the operation so save our state saveWidgetValues(); boolean success = false; File exportFile = new File(getDestinationValue()); if (!ensureTargetIsValid(exportFile)) { return false; } if (activeEditor != null && activeEditor instanceof EntryEditor) { ((EntryEditor)activeEditor).exportEntries(exportFile); success = true; } else { setErrorMessage("no active editor or invalid editor"); } // TODO: where to get the entries? (managed by editor) // Storage.exportEntries(entries, exportFile); if (success) { saveWidgetValues(); } return success; } protected void restoreWidgetValues() { System.out.println("restoreWidgetValues"); IDialogSettings settings = getDialogSettings(); System.out.println(" getDialogSettings returned null!"); if (settings != null) { String[] directoryNames = settings .getArray(STORE_DESTINATION_NAMES_ID); if (directoryNames != null) { // destination setDestinationValue(directoryNames[0]); for (int i = 0; i < directoryNames.length; i++) { addDestinationItem(directoryNames[i]); } String current = settings.get(STORE_DESTINATION_ID); if (current != null) { setDestinationValue(current); } // options if (overwriteExistingFilesCheckbox != null) { overwriteExistingFilesCheckbox.setSelection(settings .getBoolean(STORE_OVERWRITE_EXISTING_FILES_ID)); } } } } protected void saveWidgetValues() { // allow subclasses to save values internalSaveWidgetValues(); } protected void internalSaveWidgetValues() { System.out.println("internalSaveWidgetValues"); // update directory names history IDialogSettings settings = getDialogSettings(); System.out.println(" getDialogSettings returned null!"); if (settings != null) { String[] directoryNames = settings .getArray(STORE_DESTINATION_NAMES_ID); if (directoryNames == null) { directoryNames = new String[0]; } directoryNames = addToHistory(directoryNames, getDestinationValue()); settings.put(STORE_DESTINATION_NAMES_ID, directoryNames); String current = getDestinationValue(); if (current != null && !current.equals("")) { //$NON-NLS-1$ settings.put(STORE_DESTINATION_ID, current); } // options if (overwriteExistingFilesCheckbox != null) { settings.put(STORE_OVERWRITE_EXISTING_FILES_ID, overwriteExistingFilesCheckbox.getSelection()); } } } protected String[] addToHistory(String[] history, String newEntry) { List<String> l = new ArrayList<String>(Arrays.asList(history)); addToHistory(l, newEntry); String[] r = new String[l.size()]; l.toArray(r); return r; } protected void addToHistory(List<String> history, String newEntry) { history.remove(newEntry); history.add(0, newEntry); // since only one new item was added, we can be over the limit // by at most one item if (history.size() > COMBO_HISTORY_LENGTH) { history.remove(COMBO_HISTORY_LENGTH); } } public String queryOverwrite(String pathString) { System.out.println("queryOverwrite"); Path path = new Path(pathString); String messageString; // Break the message up if there is a file name and a directory // and there are at least 2 segments. if (path.getFileExtension() == null || path.segmentCount() < 2) { messageString = "TODO: path exists mesg"; } else { messageString = "TODO: ok to overwrite msg"; } final MessageDialog dialog = new MessageDialog(getContainer() .getShell(), "TODO: questio msg", null, messageString, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0); String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL }; // run in syncExec because callback is from an operation, // which is probably not running in the UI thread. getControl().getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog .getReturnCode()]; } protected boolean ensureTargetIsValid(File file) { if (file.exists()) { if (!getOverwriteExisting()) { String msg = "TODO: ok to overwrite?"; if (!queryYesNoQuestion(msg)) { return false; } } file.delete(); } else if (!file.isDirectory()) { File parent = file.getParentFile(); if (parent != null) { file.getParentFile().mkdirs(); } } return true; } private boolean getOverwriteExisting() { return overwriteExistingFilesCheckbox.getSelection(); } protected boolean queryYesNoQuestion(String message) { MessageDialog dialog = new MessageDialog(getContainer().getShell(), "TODO: yes/no question", (Image) null, message, MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); // ensure yes is the default return dialog.open() == 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -