descriptionpropertysection.java

来自「基于Java RCP 应用的属性编辑, 可以对RCP 程序进行属性的设置」· Java 代码 · 共 71 行

JAVA
71
字号
package commonproperties.tab;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import commonproperties.model.FileModel;

public class DescriptionPropertySection extends AbstractPropertySection {

	private FileModel fileModel = null;

	private Text descriptionText;

	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);

		parent.setLayout(new GridLayout(1, false));
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));

		Section section = getWidgetFactory().createSection(parent,
				Section.TITLE_BAR | Section.TWISTIE);
		section.setText("description");
		section.setLayout(new GridLayout(1, false));
		section.setLayoutData(new GridData(GridData.FILL_BOTH));

		Composite composite = getWidgetFactory().createComposite(section,
				SWT.NONE);
		composite.setLayout(new GridLayout(1, false));
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));

		Group group = getWidgetFactory().createGroup(composite, "description");
		group.setLayout(new GridLayout(1, false));
		group.setLayoutData(new GridData(GridData.FILL_BOTH));

		descriptionText = getWidgetFactory().createText(group, "",
				SWT.MULTI | SWT.BORDER);
		descriptionText.setText("");
		descriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));

		section.setClient(composite);
	}

	@Override
	public void refresh() {
		super.refresh();
		descriptionText.setText(fileModel.getDescription());
	}

	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
		super.setInput(part, selection);
		Object obj = ((IStructuredSelection) selection).getFirstElement();
		if (obj instanceof FileModel) {
			fileModel = (FileModel) obj;
		}
	}

}

⌨️ 快捷键说明

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