diff options
Diffstat (limited to 'org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java')
-rw-r--r-- | org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java b/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java deleted file mode 100644 index c703e302d..000000000 --- a/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java +++ /dev/null @@ -1,139 +0,0 @@ -/* -* Common -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* Kangho Kim <kh5325.kim@samsung.com> -* -* 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. -* -* Contributors: -* - S-Core Co., Ltd -* -*/ - -package org.tizen.common.handler; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.tizen.common.manager.StatusLineMessageManager; -import org.tizen.common.model.ITableModel; -import org.tizen.common.util.DialogUtil; - - - -public class SaveFileHandler extends AbstractHandler { - private IViewPart part; - private TableViewer viewer; - private String fileName; - private Shell shell; - private StatusLineMessageManager statusLine; - - private final String title = Messages.SaveFileHandler_0; - private final String PARAMETER_ID = "org.tizen.common.command.saveFile.parameter"; //$NON-NLS-1$ - - - public Object execute(ExecutionEvent event) throws ExecutionException { - - part = (IViewPart)HandlerUtil.getActivePart(event); - shell = part.getSite().getShell(); - statusLine = new StatusLineMessageManager(part); - - viewer = (TableViewer)part.getSite().getSelectionProvider(); - String extension = event.getParameter(PARAMETER_ID); - - if(!hasRecord()) - return null; - - try { - saveFile(extension); - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - - private void saveFile(String extension) throws InvocationTargetException, InterruptedException { - fileName = getSaveFileName(extension); - - if(fileName==null) - return; - - if(!fileName.endsWith("."+extension)) //$NON-NLS-1$ - fileName= fileName+"."+extension; //$NON-NLS-1$ - - if(!(new File(fileName).getParentFile().canWrite())){ - DialogUtil.openErrorDialog(Messages.SaveFileHandler_4); - return; - } - - part.getSite().getWorkbenchWindow().run(false, false, new IRunnableWithProgress(){ - public void run(IProgressMonitor monitor) { - monitor.beginTask(Messages.SaveFileHandler_5, 100); - writeRecord(); - monitor.done(); - } - }); - - showRecordCount(); - - } - - private String getSaveFileName(String extension) { - String[] extFilter = {"*."+extension,"*.*"}; //$NON-NLS-1$ //$NON-NLS-2$ - - FileDialog dialog = new FileDialog(shell, SWT.SAVE); - dialog.setFilterExtensions(extFilter); - dialog.setText(title); - dialog.setOverwrite(true); - dialog.setFileName("untitled."+extension); //$NON-NLS-1$ - dialog.setFilterPath(System.getProperty("user.home")); //$NON-NLS-1$ - - return dialog.open(); - } - - private void writeRecord() { - ITableModel model = (ITableModel) viewer.getInput(); - model.save(fileName); - } - - private void showRecordCount() { - int size = ((ITableModel) viewer.getInput()).size(); - statusLine.setMessage(Messages.SaveFileHandler_1+size+Messages.SaveFileHandler_11 + fileName); - } - - private boolean hasRecord() { - int size = ((ITableModel) viewer.getInput()).size(); - if(size==0){ - statusLine.setErrorMessage(Messages.SaveFileHandler_12); - return false; - }else - statusLine.setErrorMessage(""); //$NON-NLS-1$ - return true; - } -} - |