?? jadpropertieseditorpage.java
字號:
/**
* Copyright (c) 2003-2005 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.editor.jad;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.model.DescriptorPropertyDescription;
/**
* An editor part page that may be added to the JAD editor.
* <p />
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.10 $
* <br>
* $Date: 2006/02/11 21:27:36 $
* <br>
* @author Craig Setera
*/
public abstract class JADPropertiesEditorPage extends AbstractJADEditorPage {
// The descriptors being editted
private DescriptorPropertyDescription[] descriptors;
// The field editors in use
private FieldEditor[] fieldEditors;
// To handle the change from the internal ComboFieldEditor used prior
// to 3.3. This probably should have been better handled in the first
// place, but now that it is moving to an externally available class,
// it isn't worth replicating
private Class comboFieldEditorClass;
private Constructor comboEditorConstructor;
/**
* Constructor
*/
public JADPropertiesEditorPage(
JADEditor editor,
String id,
String title,
DescriptorPropertyDescription[] descriptors)
{
super(editor, id, title);
this.descriptors = descriptors;
}
/**
* @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
*/
public void doSave(IProgressMonitor monitor) {
monitor.setTaskName(getTitle());
for (int i = 0; i < fieldEditors.length; i++) {
fieldEditors[i].store();
}
setDirty(false);
}
/**
* @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
*/
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
Composite composite = createSectionComposite(managedForm);
composite.setLayout(new GridLayout(2, false));
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
fieldEditors = new FieldEditor[descriptors.length];
for (int i = 0; i < descriptors.length; i++) {
switch (descriptors[i].getDataType()) {
case DescriptorPropertyDescription.DATATYPE_INT:
fieldEditors[i] = createIntegerFieldEditor(toolkit, composite, descriptors[i]);
break;
case DescriptorPropertyDescription.DATATYPE_LIST:
fieldEditors[i] = createComboFieldEditor(toolkit, composite, descriptors[i]);
break;
case DescriptorPropertyDescription.DATATYPE_URL:
case DescriptorPropertyDescription.DATATYPE_STRING:
default:
fieldEditors[i] = createStringFieldEditor(toolkit, composite, descriptors[i]);
break;
}
Label label = fieldEditors[i].getLabelControl(composite);
toolkit.adapt(label, false, false);
// Listen for property change events on the editor
fieldEditors[i].setPropertyChangeListener(new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(FieldEditor.VALUE)) {
setDirty(true);
}
}
});
}
// Adapt the Combo instances...
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
Control control = children[i];
if (control instanceof Combo) {
toolkit.adapt(control, false, false);
}
}
updateEditComponents();
addContextHelp(composite);
}
protected void addContextHelp(Composite c)
{
}
/**
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
public void setFocus() {
if (fieldEditors.length > 0) {
fieldEditors[0].setFocus();
}
}
/**
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
protected void setInput(IEditorInput input) {
super.setInput(input);
updateEditComponents();
setDirty(false);
}
/**
* Create a new combo field editor.
*
* @param toolkit
* @param composite
* @param description
* @return
*/
private FieldEditor createComboFieldEditor(
FormToolkit toolkit,
Composite composite,
DescriptorPropertyDescription description)
{
if (comboFieldEditorClass == null) {
initializeComboFieldEditorSupport();
}
ListDescriptorPropertyDescription listDescription =
(ListDescriptorPropertyDescription) description;
FieldEditor editor = null;
try {
editor = (FieldEditor) comboEditorConstructor.newInstance(
new Object[] {
listDescription.getPropertyName(),
listDescription.getDisplayName(),
listDescription.getNamesAndValues(),
composite
});
} catch (IllegalArgumentException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
} catch (InstantiationException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
} catch (IllegalAccessException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
} catch (InvocationTargetException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
}
return editor;
}
/**
* Create a new integer field editor.
*
* @param toolkit
* @param parent
* @param descriptor
* @return
*/
private IntegerFieldEditor createIntegerFieldEditor(
FormToolkit toolkit,
Composite parent,
DescriptorPropertyDescription descriptor)
{
IntegerFieldEditor integerEditor =
new IntegerFieldEditor(
descriptor.getPropertyName(),
descriptor.getDisplayName(),
parent);
toolkit.adapt(integerEditor.getTextControl(parent), true, true);
return integerEditor;
}
/**
* Create a new String field editor.
*
* @param toolkit
* @param parent
* @param descriptor
* @return
*/
private StringFieldEditor createStringFieldEditor(
FormToolkit toolkit,
Composite parent,
DescriptorPropertyDescription descriptor)
{
StringFieldEditor editor =
new StringFieldEditor(
descriptor.getPropertyName(),
descriptor.getDisplayName(),
parent);
toolkit.adapt(editor.getTextControl(parent), true, true);
return editor;
}
/**
* Resolve the appropriate combo field editor class to be used
* dependent on the version.
*/
private void initializeComboFieldEditorSupport() {
String[] names = new String[] {
"org.eclipse.jdt.internal.debug.ui.launcher.ComboFieldEditor",
"org.eclipse.jface.preference.ComboFieldEditor",
};
for (int i = 0; (comboFieldEditorClass == null) && (i < names.length); i++) {
String name = names[i];
try {
comboFieldEditorClass = Class.forName(name);
comboEditorConstructor = comboFieldEditorClass.getConstructors()[0];
} catch (ClassNotFoundException e) {
} catch (SecurityException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
}
}
}
/**
* Update the application descriptor the components
* are handling
*/
private void updateEditComponents() {
if (fieldEditors != null) {
IPreferenceStore store = getPreferenceStore();
for (int i = 0; i < fieldEditors.length; i++) {
FieldEditor fieldEditor = fieldEditors[i];
fieldEditor.setPreferenceStore(store);
fieldEditor.load();
}
}
}
/**
* @see eclipseme.ui.internal.editor.jad.AbstractJADEditorPage#getSectionDescription()
*/
protected String getSectionDescription() {
return null;
}
/**
* @see eclipseme.ui.internal.editor.jad.AbstractJADEditorPage#getSectionTitle()
*/
protected String getSectionTitle() {
return null;
}
/**
* @see eclipseme.ui.internal.editor.jad.AbstractJADEditorPage#editorInputChanged()
*/
void editorInputChanged() {
updateEditComponents();
}
/**
* @see eclipseme.ui.internal.editor.jad.AbstractJADEditorPage#isManagingProperty(java.lang.String)
*/
boolean isManagingProperty(String property) {
boolean manages = false;
for (int i = 0; i < descriptors.length; i++) {
DescriptorPropertyDescription desc = descriptors[i];
if (property.equals(desc.getPropertyName())) {
manages = true;
break;
}
}
return manages;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -