⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devicelibrarieseditorpage.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			IClasspathEntry entry = (IClasspathEntry) doGetValue();
			if (entry != null) {
				newEntry = BuildPathDialogAccess.configureJavadocLocation(shell, entry);
			}
			
			return newEntry;
		}

		/**
		 * @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) {
	        	IClasspathEntry entry = (IClasspathEntry) value;
	            URL url = getJavadocURL(entry);
	            if (url != null) {
	            	text = url.toString();
	            }
	        }
	        defaultLabel.setText(text);
		}
	}
	
	// A dialog cell editor for selecting the source locations for a library
	private class SourceAttachDialogCellEditor extends DialogCellEditor {
		public SourceAttachDialogCellEditor(Composite parent) {
			super(parent);
		}

		protected Object openDialogBox(Control cellEditorWindow) {
			Shell shell = cellEditorWindow.getShell();
			
			IClasspathEntry newEntry = null;
			IClasspathEntry entry = (IClasspathEntry) doGetValue();
			if (entry != null) {
				newEntry = BuildPathDialogAccess.configureSourceAttachment(shell, entry);
			}
			
			return newEntry;
		}

		/**
		 * @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) {
	        	IClasspathEntry entry = (IClasspathEntry) value;
	        	IPath attachPath = entry.getSourceAttachmentPath();
	            if (attachPath != null) {
	            	text = attachPath.toString();
	            }
	        }
	        defaultLabel.setText(text);
		}
	}
	
	// Widgets
	private TableViewer viewer;

	/**
	 * Construct the editor page.
	 * 
	 * @param parent
	 * @param style
	 */
	public DeviceLibrariesEditorPage(Composite parent, int style) {
		super(parent, style);
	}

	/**
	 * @see eclipseme.ui.internal.device.editor.AbstractDeviceEditorPage#commitDeviceChanges()
	 */
	public void commitDeviceChanges() {
		Object viewerInput = viewer.getInput();
		if (viewerInput instanceof Classpath) {
			editDevice.setClasspath((Classpath) viewerInput);
		}
	}

	/**
	 * @see eclipseme.ui.internal.device.editor.AbstractDeviceEditorPage#getDescription()
	 */
	public String getDescription() {
		return "Specify the libraries that are available for the device";
	}

	/**
	 * @see eclipseme.ui.internal.device.editor.AbstractDeviceEditorPage#getTitle()
	 */
	public String getTitle() {
		return "Libraries";
	}

	/**
	 * @see eclipseme.ui.internal.device.editor.AbstractDeviceEditorPage#setDevice(eclipseme.core.model.device.IDevice)
	 */
	public void setDevice(IDevice device) {
		super.setDevice(device);
		
		if (device instanceof AbstractDevice) {
			Classpath classpath = ((AbstractDevice) device).getClasspath();
			try {
				Classpath clone = (Classpath) PersistableUtilities.clonePersistable(classpath);
				viewer.setInput(clone);
			} catch (PersistenceException e) {
				EclipseMECorePlugin.log(IStatus.WARNING, "Error cloning device classpath", e);
			}
		}
	}

	/**
	 * Return the javadoc url for the specified entry.
	 * 
	 * @param entry
	 * @return
	 */
	protected URL getJavadocURL(IClasspathEntry entry) {
		URL url = null;

		if ((entry != null) && (entry.getExtraAttributes() != null)) {
			IClasspathAttribute[] attributes = entry.getExtraAttributes();
			for (int i = 0; i < attributes.length; i++) {
				IClasspathAttribute attribute = attributes[i];
				if (attribute.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) {
					try {
						url = new URL(attribute.getValue());
					} catch (MalformedURLException e) {
						EclipseMECorePlugin.log(IStatus.WARNING, "Error getting new Javadoc URL", e);
					}
				}
			}
		}
		
		return url;
	}

	/**
	 * Create the devices table viewer.
	 * 
	 * @param parent
	 */
	private TableViewer createTableViewer(Composite composite) {
		int styles = 
			SWT.SINGLE | SWT.V_SCROLL |  
			SWT.BORDER | SWT.FULL_SELECTION;
		Table table = new Table(composite, styles);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		// Wire up the viewer
		TableViewer viewer = new TableViewer(table);
		viewer.setContentProvider(new DeviceClasspathContentProvider());
		viewer.setLabelProvider(new LibraryLabelProvider());
		
		IDialogSettings viewerSettings = 
			EclipseMEUIPlugin.getDialogSettings("deviceLibrariesViewerSettings");
		TableViewerConfiguration viewerConfiguration =
			new TableViewerConfiguration(viewerSettings, DEFAULT_TABLE_WIDTH, COLUMN_INFO, 0);
		viewerConfiguration.configure(viewer);
		
		// Wire up the cell modification handling
		viewer.setCellModifier(new CellModifier());
		viewer.setColumnProperties(PROPERTIES);
		viewer.setCellEditors(new CellEditor[] {
			new ArchiveFileSelectionDialogCellEditor(table, false),
			new ArchiveFileSelectionDialogCellEditor(table, true),
			new APIFileSelectionDialogCellEditor(table),
			new JavadocAttachDialogCellEditor(table),
			new SourceAttachDialogCellEditor(table), 
		});
		
		return viewer;
	}

	/**
	 * @see eclipseme.ui.internal.device.editor.AbstractDeviceEditorPage#addPageControls(org.eclipse.swt.widgets.Composite)
	 */
	protected void addPageControls(Composite parent) {
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
		parent.setLayout(new GridLayout(2, false));

		GridData gridData = new GridData(GridData.FILL_BOTH);
		gridData.minimumWidth = DEFAULT_TABLE_WIDTH;
		gridData.heightHint = 400;
		viewer = createTableViewer(parent);
		viewer.getTable().setLayoutData(gridData);

		Composite buttonComposite = new Composite(parent, SWT.NONE);
		buttonComposite.setLayout(new GridLayout(1, true));
		buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
		
		Button addButton = new Button(buttonComposite, SWT.PUSH);
		addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		addButton.setText("Add...");
		addButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleAddButton();
			}
		});
		
		final Button removeButton = new Button(buttonComposite, SWT.PUSH);
		removeButton.setEnabled(false);
		removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		removeButton.setText("Remove");
		removeButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleRemoveButton();
			}
		});
		
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(SelectionChangedEvent event) {
				ILibrary selectedLibrary = getSelectedLibrary();
				removeButton.setEnabled(selectedLibrary != null);
			}
		});
	}

	/**
	 * Return the API's for the library.
	 * 
	 * @param library
	 * @return
	 */
	private String getApisLabel(API[] apis) {
		StringBuffer sb = new StringBuffer();
		
		for (int i = 0; i < apis.length; i++) {
			API api = apis[i];
			if (i != 0) {
				sb.append(", ");
			}
			
			sb.append(api);
		}
		
		return sb.toString();
	}
	
	/**
	 * Return the classpath being edited.
	 * 
	 * @return
	 */
	private Classpath getClasspath() {
		return (Classpath) viewer.getInput();
	}
	
	/**
	 * Return the currently selected library or <code>null</code> if
	 * nothing is selected.
	 * 
	 * @return
	 */
	private ILibrary getSelectedLibrary() {
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
		return (selection.size() > 0) ? 
			(ILibrary) selection.getFirstElement() :
			null;
	}
	
	/**
	 * Handle the add button being pressed.
	 */
	private void handleAddButton() {
		File archiveFile = promptForArchiveFile(getShell(), null);
		if (archiveFile != null) {
			LibraryImporter importer = new LibraryImporter();
			ILibrary library = importer.createLibraryFor(archiveFile);
			getClasspath().addEntry(library);
			viewer.refresh();
		}
	}

	/**
	 * Handle the remove button being pressed.
	 */
	private void handleRemoveButton() {
		if (MessageDialog.openConfirm(
			getShell(), 
			"Confirm Remove", 
			"Remove the selected library?")) 
		{
			ILibrary selectedLibrary = getSelectedLibrary();
			getClasspath().removeEntry(selectedLibrary);
			viewer.refresh();
		}
	}
	
	/**
	 * Prompt for an archive file.
	 * 
	 * @param shell
	 * @param currentFile
	 * @return
	 */
	private File promptForArchiveFile(Shell shell, File currentFile) {
		FileDialog fileDialog = new FileDialog(shell);
		fileDialog.setFilterNames(new String[] { "*.jar;*.zip" });
		
		if ((currentFile != null) && (currentFile.exists())) {
			fileDialog.setFileName(currentFile.toString());
		}
		
		String filename = fileDialog.open();
		return (filename == null) ? null : new File(filename);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -