?? devicelibrarieseditorpage.java
字號:
/**
* Copyright (c) 2003-2006 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.ui.internal.device.editor;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import eclipseme.core.importer.LibraryImporter;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.model.API;
import eclipseme.core.model.Classpath;
import eclipseme.core.model.ILibrary;
import eclipseme.core.model.device.IDevice;
import eclipseme.core.model.impl.AbstractDevice;
import eclipseme.core.model.impl.Library;
import eclipseme.core.persistence.PersistableUtilities;
import eclipseme.core.persistence.PersistenceException;
import eclipseme.ui.internal.EclipseMEUIPlugin;
import eclipseme.ui.viewers.TableColumnInfo;
import eclipseme.ui.viewers.TableViewerConfiguration;
/**
* Implements an editor page for editing the libraries available
* for the device being edited.
* <p />
* Copyright (c) 2003-2006 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.6 $
* <br>
* $Date: 2007/01/20 22:19:39 $
* <br>
* @author Craig Setera
*/
public class DeviceLibrariesEditorPage extends AbstractDeviceEditorPage {
private static final Object[] NO_ELEMENTS = new Object[0];
// Column property names
private static final String PROP_FILE = "file";
private static final String PROP_PATH = "path";
private static final String PROP_APIS = "apis";
private static final String PROP_JAVADOC = "javadoc";
private static final String PROP_SOURCE = "source";
// All of the properties in order
private static final String[] PROPERTIES =
new String[] { PROP_FILE, PROP_PATH, PROP_APIS, PROP_JAVADOC, PROP_SOURCE };
// Column information structure
private static final int DEFAULT_TABLE_WIDTH = 650;
private static final TableColumnInfo[] COLUMN_INFO = new TableColumnInfo[] {
new TableColumnInfo("File", 15f, null),
new TableColumnInfo("Path", 20f, null),
new TableColumnInfo("APIs", 15f, null),
new TableColumnInfo("Javadoc", 25f, null),
new TableColumnInfo("Source", 25f, null),
};
// A cell modifier implementation for the device libraries editor
private class CellModifier implements ICellModifier {
public boolean canModify(Object element, String property) {
return true;
}
public Object getValue(Object element, String property) {
Object value = null;
Library library = (Library) element;
switch (getColumnIndex(property)) {
case 0:
case 1:
value = library.getLibraryFile();
break;
case 2:
value = library.getAPIs();
break;
case 3:
case 4:
value = library.toClasspathEntry();
break;
}
return value;
}
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
Library library = (Library) item.getData();
switch (getColumnIndex(property)) {
case 0:
case 1:
library.setLibraryFile((File) value);
break;
case 2:
library.setApis((API[]) value);
break;
case 3:
{
URL url = getJavadocURL((IClasspathEntry) value);
library.setJavadocURL(url);
}
break;
case 4:
{
IClasspathEntry entry = (IClasspathEntry) value;
library.setSourceAttachmentPath(entry.getSourceAttachmentPath());
library.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath());
}
break;
}
viewer.refresh(library, true);
}
/**
* Return the column index for the property.
*
* @param property
* @return
*/
private int getColumnIndex(String property) {
int index = -1;
for (int i = 0; i < PROPERTIES.length; i++) {
if (PROPERTIES[i].equals(property)) {
index = i;
break;
}
}
return index;
}
}
// Content provider for a device's classpath entries
private class DeviceClasspathContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
Object[] elements = NO_ELEMENTS;
if (inputElement instanceof Classpath) {
Classpath classpath = (Classpath) inputElement;
elements = classpath.getEntries();
}
return elements;
}
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}
// Cell editor for editing library APIs
private class APIFileSelectionDialogCellEditor extends DialogCellEditor {
public APIFileSelectionDialogCellEditor(Composite parent) {
super(parent);
}
protected Object openDialogBox(Control cellEditorWindow) {
LibraryApiEditorDialog dialog =
new LibraryApiEditorDialog(cellEditorWindow.getShell());
API[] apis = (API[]) doGetValue();
dialog.setAPIs(apis);
return (dialog.open() == Dialog.OK) ? dialog.getAPIs() : apis;
}
/**
* @see org.eclipse.jface.viewers.DialogCellEditor#updateContents(java.lang.Object)
*/
protected void updateContents(Object value) {
Label defaultLabel = getDefaultLabel();
if (defaultLabel == null)
return;
String text = "";//$NON-NLS-1$
if (value != null) {
API[] apis = (API[]) value;
text = getApisLabel(apis);
}
defaultLabel.setText(text);
}
}
// Cell editor for selecting an archive file
private class ArchiveFileSelectionDialogCellEditor extends DialogCellEditor {
private boolean filepath;
public ArchiveFileSelectionDialogCellEditor(Composite parent, boolean filepath) {
super(parent);
this.filepath = filepath;
}
protected Object openDialogBox(Control cellEditorWindow) {
File value = (File) doGetValue();
return promptForArchiveFile(cellEditorWindow.getShell(), value);
}
/**
* @see org.eclipse.jface.viewers.DialogCellEditor#updateContents(java.lang.Object)
*/
protected void updateContents(Object value) {
Label defaultLabel = getDefaultLabel();
if (defaultLabel == null)
return;
String text = "";//$NON-NLS-1$
if (value != null) {
File file = (File) value;
text = filepath ? file.getParent() : file.getName();
}
defaultLabel.setText(text);
}
}
// Label provider for Library instances
private class LibraryLabelProvider extends LabelProvider implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
Library library = (Library) element;
String text = "";
if (library != null) {
switch (columnIndex) {
case 0:
text = library.getLibraryFile().getName();
break;
case 1:
text = library.getLibraryFile().getParent();
break;
case 2:
text = getApisLabel(library.getAPIs());
break;
case 3:
{
URL url = library.getJavadocURL();
if (url != null) {
text = url.toString();
}
}
break;
case 4:
{
IPath path = library.getSourceAttachmentPath();
if (path != null) {
text = path.toString();
}
}
break;
}
}
return text;
}
}
// A dialog cell editor for selecting the javadoc URL for a library
private class JavadocAttachDialogCellEditor extends DialogCellEditor {
public JavadocAttachDialogCellEditor(Composite parent) {
super(parent);
}
protected Object openDialogBox(Control cellEditorWindow) {
Shell shell = cellEditorWindow.getShell();
IClasspathEntry newEntry = null;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -