01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.readmetool;
11:
12: import java.io.ByteArrayInputStream;
13:
14: import org.eclipse.core.resources.IFile;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.ui.part.IDropActionDelegate;
17:
18: /**
19: * Adapter for handling the dropping of readme segments into
20: * another plugin. In this case, we expect the segments
21: * to be dropped onto <code>IFile</code> object, or an adapter
22: * that supports <code>IFile</code>.
23: */
24: public class ReadmeDropActionDelegate implements IDropActionDelegate {
25: public static final String ID = "org_eclipse_ui_examples_readmetool_drop_actions"; //$NON-NLS-1$
26:
27: /** (non-Javadoc)
28: * Method declared on IDropActionDelegate
29: */
30: public boolean run(Object source, Object target) {
31: if (source instanceof byte[] && target instanceof IFile) {
32: IFile file = (IFile) target;
33: try {
34: file.appendContents(new ByteArrayInputStream(
35: (byte[]) source), false, true, null);
36: } catch (CoreException e) {
37: System.out
38: .println(MessageUtil
39: .getString("Exception_in_readme_drop_adapter") + e.getStatus().getMessage()); //$NON-NLS-1$
40: return false;
41: }
42: return true;
43: }
44: return false;
45: }
46: }
|