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

📄 filemodelpropertysource.java

📁 基于Java RCP 应用的属性编辑, 可以对RCP 程序进行属性的设置
💻 JAVA
字号:
package commonproperties.model;

import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

import commonproperties.propdes.DescriptionPropertyDescriptor;

public class FileModelPropertySource implements IPropertySource {

	private static final String DESCRIPTION_ID = "description";

	private static final String IS_READ_ONLY_ID = "isReadOnly";

	private static final String LAST_MODIFIED_TIME_ID = "lastModifiedTime";

	private static final String DIR_ID = "dir";

	private static final String PARENT_ID = "parent";

	private static final String PATH_CATEGORY = "path";

	private static final String ATTR_CATEGORY = "attribute";

	private static final String DESC_CATEGORY = "description";

	private FileModel model = null;

	public FileModelPropertySource(FileModel model) {
		this.model = model;
	}

	public Object getEditableValue() {
		// TODO Auto-generated method stub
		return null;
	}

	public IPropertyDescriptor[] getPropertyDescriptors() {
		IPropertyDescriptor[] descriptors = new IPropertyDescriptor[5];
		descriptors[0] = new TextPropertyDescriptor(PARENT_ID, "parent");
		descriptors[1] = new TextPropertyDescriptor(DIR_ID, "dir");
		descriptors[2] = new TextPropertyDescriptor(LAST_MODIFIED_TIME_ID,
				"lastModifiedTime");
		descriptors[3] = new ComboBoxPropertyDescriptor(IS_READ_ONLY_ID,
				"isReadOnly", new String[] { "true", "false" });
		descriptors[4] = new DescriptionPropertyDescriptor(DESCRIPTION_ID,
				"description", model.getDescription());
		
		//set parent's catelog
		((PropertyDescriptor)descriptors[0] ).setCategory(PATH_CATEGORY);
		//set dir's catelog
		((PropertyDescriptor)descriptors[1] ).setCategory(PATH_CATEGORY);
		//set last modified time's catelog
		((PropertyDescriptor)descriptors[2] ).setCategory(ATTR_CATEGORY);
		//set readOnly's catelog
		((PropertyDescriptor)descriptors[3] ).setCategory(ATTR_CATEGORY);
		//set description's catelog
		((PropertyDescriptor)descriptors[4] ).setCategory(DESC_CATEGORY);
		
		return descriptors;
	}

	public Object getPropertyValue(Object id) {
		if (id.equals(PARENT_ID))
			return model.getFile().getParent();
		else if (id.equals(DIR_ID))
			return model.getFile().getAbsolutePath();
		else if (id.equals(LAST_MODIFIED_TIME_ID))
			return model.getFile().lastModified();
		else if (id.equals(IS_READ_ONLY_ID)) {
//			if (model.getFile().canWrite())
//				return 1;
//			else
//				return 0;
			return new SubPropertySource();
		} else if (id.equals(DESCRIPTION_ID))
			return "description";
		return null;
	}

	public boolean isPropertySet(Object id) {
		if (id.equals(DESCRIPTION_ID))
			return true;
		return false;
	}

	public void resetPropertyValue(Object id) {
		if (id.equals(DESCRIPTION_ID))
			setPropertyValue(DESCRIPTION_ID, "this file's name is: "
					+ model.getFile().getName());

	}

	public void setPropertyValue(Object id, Object value) {
		if (id.equals(DESCRIPTION_ID))
			model.setDescription(value.toString());
	}

}

⌨️ 快捷键说明

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