|
Lines 1-5
Link Here
|
|
|
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 1 |
package org.eclipse.wst.xml.ui.internal.hyperlink; |
11 |
package org.eclipse.wst.xml.ui.internal.hyperlink; |
| 2 |
|
12 |
|
|
|
13 |
import java.io.IOException; |
| 3 |
import java.io.InputStream; |
14 |
import java.io.InputStream; |
| 4 |
import java.net.URL; |
15 |
import java.net.URL; |
| 5 |
|
16 |
|
|
Lines 8-14
Link Here
|
| 8 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
| 9 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.IStatus; |
| 10 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.core.runtime.Path; |
|
|
22 |
import org.eclipse.core.runtime.Platform; |
| 11 |
import org.eclipse.core.runtime.Status; |
23 |
import org.eclipse.core.runtime.Status; |
|
|
24 |
import org.eclipse.core.runtime.content.IContentType; |
| 12 |
import org.eclipse.jface.resource.ImageDescriptor; |
25 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 13 |
import org.eclipse.jface.text.IRegion; |
26 |
import org.eclipse.jface.text.IRegion; |
| 14 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
27 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
|
Lines 152-158
Link Here
|
| 152 |
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() |
165 |
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() |
| 153 |
*/ |
166 |
*/ |
| 154 |
public String getHyperlinkText() { |
167 |
public String getHyperlinkText() { |
| 155 |
return NLS.bind(XMLUIMessages.Open, fURL.toString()); |
168 |
String path = fURL.toString(); |
|
|
169 |
if (path.length() > 60) { |
| 170 |
path = path.substring(0, 25) + "..." + path.substring(path.length() - 25, path.length()); |
| 171 |
} |
| 172 |
final String editorLabel = getEditorLabel(); |
| 173 |
if (editorLabel != null) |
| 174 |
return NLS.bind(XMLUIMessages.Open_With, path, editorLabel); |
| 175 |
return NLS.bind(XMLUIMessages.Open, path); |
| 176 |
} |
| 177 |
|
| 178 |
protected String getEditorLabel() { |
| 179 |
IEditorDescriptor descriptor = getEditorDescriptor(); |
| 180 |
return descriptor != null ? descriptor.getLabel() : null; |
| 181 |
} |
| 182 |
|
| 183 |
private IEditorDescriptor getEditorDescriptor() { |
| 184 |
final URLStorage storage = new URLStorage(fURL); |
| 185 |
final String path = fURL.getPath(); |
| 186 |
String name = null; |
| 187 |
if (path != null) |
| 188 |
name = new Path(fURL.getPath()).lastSegment(); |
| 189 |
|
| 190 |
IContentType contentType= null; |
| 191 |
try { |
| 192 |
InputStream is = null; |
| 193 |
try { |
| 194 |
is = storage.getContents(); |
| 195 |
contentType= Platform.getContentTypeManager().findContentTypeFor(is, name); |
| 196 |
} finally { |
| 197 |
if (is != null) { |
| 198 |
is.close(); |
| 199 |
} |
| 200 |
} |
| 201 |
} catch (CoreException ex) { |
| 202 |
// continue without content type |
| 203 |
} catch (IOException ex) { |
| 204 |
// continue without content type |
| 205 |
} |
| 206 |
|
| 207 |
return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(name, contentType); |
| 156 |
} |
208 |
} |
| 157 |
|
209 |
|
| 158 |
/* |
210 |
/* |
|
Lines 163-171
Link Here
|
| 163 |
public void open() { |
215 |
public void open() { |
| 164 |
if (fURL != null) { |
216 |
if (fURL != null) { |
| 165 |
IEditorInput input = new StorageEditorInput(new URLStorage(fURL)); |
217 |
IEditorInput input = new StorageEditorInput(new URLStorage(fURL)); |
| 166 |
IEditorDescriptor descriptor; |
|
|
| 167 |
try { |
218 |
try { |
| 168 |
descriptor = IDE.getEditorDescriptor(input.getName()); |
219 |
final IEditorDescriptor descriptor = getEditorDescriptor(); |
| 169 |
if (descriptor != null) { |
220 |
if (descriptor != null) { |
| 170 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
221 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 171 |
IDE.openEditor(page, input, descriptor.getId(), true); |
222 |
IDE.openEditor(page, input, descriptor.getId(), true); |