use of org.eclipse.jface.viewers.EditingSupport in project liferay-ide by liferay.
the class FindBreakingChangesPage method _createColumns.
private void _createColumns(final TableViewer problemsViewer) {
final String[] titles = { "Resolved", "Line", "Problem" };
TableViewerColumn col0 = _createTableViewerColumn(titles[0], problemsViewer);
col0.getColumn().pack();
col0.setEditingSupport(new EditingSupport(problemsViewer) {
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new CheckboxCellEditor(problemsViewer.getTable());
}
@Override
protected Object getValue(Object element) {
return ((Problem) element).getStatus() == Problem.STATUS_RESOLVED;
}
@Override
protected void setValue(Object element, Object value) {
if (value == Boolean.TRUE) {
new MarkDoneAction().run((Problem) element, problemsViewer);
} else {
new MarkUndoneAction().run((Problem) element, problemsViewer);
}
}
});
col0.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
Problem p = (Problem) element;
if (p.getStatus() == Problem.STATUS_RESOLVED) {
return _imageChecked;
} else {
return _imageUnchecked;
}
}
@Override
public String getText(Object element) {
return null;
}
});
TableViewerColumn col1 = _createTableViewerColumn(titles[1], problemsViewer);
col1.getColumn().pack();
col1.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.lineNumber > -1 ? (p.lineNumber + "") : "";
}
});
TableViewerColumn col2 = _createTableViewerColumn(titles[2], problemsViewer);
col2.getColumn().pack();
col2.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.title;
}
@Override
public void update(ViewerCell cell) {
super.update(cell);
Table table = problemsViewer.getTable();
table.getColumn(2).pack();
}
});
TableColumnLayout tableLayout = new TableColumnLayout();
TableColumn column0 = col0.getColumn();
TableColumn column1 = col1.getColumn();
TableColumn column2 = col2.getColumn();
tableLayout.setColumnData(column0, new ColumnWeightData(50, column0.getWidth()));
tableLayout.setColumnData(column1, new ColumnWeightData(50, column1.getWidth()));
tableLayout.setColumnData(column2, new ColumnWeightData(100, column2.getWidth()));
Table table = problemsViewer.getTable();
table.getParent().setLayout(tableLayout);
}
use of org.eclipse.jface.viewers.EditingSupport in project tdq-studio-se by Talend.
the class EditSortMatchRuleNamesDialog method createMatchRuleNameColumn.
/**
* create Match Rule Name Column.
*/
private void createMatchRuleNameColumn() {
TableViewerColumn vNameColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
TableColumn nameColumn = vNameColumn.getColumn();
nameColumn.setWidth(300);
// $NON-NLS-1$
nameColumn.setText(DefaultMessagesImpl.getString("EditSortMatchRuleNamesDialog.columnName"));
vNameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((OrderMatchRule) element).getName();
}
});
vNameColumn.setEditingSupport(new EditingSupport(tableViewer) {
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor((Table) tableViewer.getControl());
}
@Override
protected Object getValue(Object element) {
return ((OrderMatchRule) element).getName();
}
@Override
protected void setValue(Object element, Object value) {
// the modified value cant not be empty
if (value != null && !StringUtils.isBlank((String) value)) {
if (!((OrderMatchRule) element).getName().equals(value)) {
setDirty(true);
getButton(OK).setEnabled(true);
}
((OrderMatchRule) element).setName((String) value);
} else {
((OrderMatchRule) element).setName(((OrderMatchRule) element).getName());
}
tableViewer.refresh();
}
});
}
use of org.eclipse.jface.viewers.EditingSupport in project rap by entirej.
the class EJRWTListRecordBlockRenderer method buildGuiComponent.
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
EJFrameworkExtensionProperties appProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
if (appProp != null) {
EJFrameworkExtensionProperties propertyGroup = appProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
if (propertyGroup != null) {
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY);
}
}
// blockCanvas.cleanLayoutVertical();
EJBlockProperties blockProperties = _block.getProperties();
EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = mainScreenProperties.getWidth();
gridData.heightHint = mainScreenProperties.getHeight();
gridData.horizontalSpan = mainScreenProperties.getHorizontalSpan();
gridData.verticalSpan = mainScreenProperties.getVerticalSpan();
gridData.grabExcessHorizontalSpace = mainScreenProperties.canExpandHorizontally();
gridData.grabExcessVerticalSpace = mainScreenProperties.canExpandVertically();
if (gridData.grabExcessHorizontalSpace)
gridData.minimumWidth = mainScreenProperties.getWidth();
if (gridData.grabExcessVerticalSpace)
gridData.minimumHeight = mainScreenProperties.getHeight();
EJFrameworkExtensionProperties rendererProp = blockProperties.getBlockRendererProperties();
blockCanvas.setLayoutData(gridData);
EJFrameworkExtensionProperties sectionProperties = null;
if (rendererProp != null) {
sectionProperties = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
}
if (sectionProperties != null && sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
int style = ExpandableComposite.TITLE_BAR;
String mode = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
style = style | ExpandableComposite.TWISTIE;
} else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
style = style | ExpandableComposite.TREE_NODE;
}
if (sectionProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
style = style | ExpandableComposite.EXPANDED;
}
Section section = toolkit.createSection(blockCanvas, style);
section.setLayoutData(gridData);
String title = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
if (title != null)
section.setText(title);
EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
if (mainScreenProperties.getDisplayFrame()) {
Group group = new Group(section, SWT.NONE);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
String frameTitle = mainScreenProperties.getFrameTitle();
if (frameTitle != null && frameTitle.length() > 0) {
group.setText(frameTitle);
}
_mainPane = new EJRWTEntireJGridPane(group, 1);
section.setClient(group);
} else {
_mainPane = new EJRWTEntireJGridPane(section, 1);
_mainPane.setLayoutData(gridData);
_mainPane.cleanLayoutHorizontal();
section.setClient(_mainPane);
}
final EJFrameworkExtensionPropertyList propertyList = sectionProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
final ToolBar toolbar = toolBarManager.createControl(section);
final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
toolbar.setCursor(handCursor);
// Cursor needs to be explicitly disposed
toolbar.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if ((handCursor != null) && (handCursor.isDisposed() == false)) {
handCursor.dispose();
}
}
});
List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
if (actionID != null) {
Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {
@Override
public void runWithEvent(Event event) {
_block.executeActionCommand(actionID, EJScreenType.MAIN);
}
};
if (actionName != null)
action.setText(actionName);
if (actionTooltip != null)
action.setDescription(actionTooltip);
if (actionImage != null && actionImage.length() > 0) {
action.setImageDescriptor((EJRWTImageRetriever.createDescriptor(actionImage)));
}
toolBarManager.add(action);
}
}
toolBarManager.update(true);
section.setTextClient(toolbar);
}
} else {
if (mainScreenProperties.getDisplayFrame()) {
Group group = new Group(blockCanvas, SWT.NONE);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
String frameTitle = mainScreenProperties.getFrameTitle();
if (frameTitle != null && frameTitle.length() > 0) {
group.setText(frameTitle);
}
_mainPane = new EJRWTEntireJGridPane(group, 1);
} else {
_mainPane = new EJRWTEntireJGridPane(blockCanvas, 1);
_mainPane.setLayoutData(gridData);
_mainPane.cleanLayoutHorizontal();
}
}
hookKeyListener(_mainPane);
int style = SWT.VIRTUAL | SWT.V_SCROLL;
if (!rendererProp.getBooleanProperty(EJRWTListRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false))
style = style | SWT.BORDER;
if (rendererProp.getBooleanProperty(EJRWTListRecordBlockDefinitionProperties.ROW_SELECTION_PROPERTY, true))
style = style | SWT.FULL_SELECTION;
else
style = style | SWT.HIDE_SELECTION;
Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
final Table table;
final boolean hideSelection = (style & SWT.HIDE_SELECTION) != 0;
// final EJRWTAbstractFilteredTable filterTree;
if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame()) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
if (displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0)
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
filterTree = new EJRWTAbstractFilteredTable(group, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
filterText = filter;
getViewer().setInput(filter);
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
@Override
public void setSelection(ISelection selection) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection, reveal);
}
};
}
};
} else {
filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
filterText = filter;
getViewer().setInput(filter);
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
@Override
public void setSelection(ISelection selection) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection, reveal);
}
};
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && ((filter == null && filteredContentProvider.getFilter() != null) || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
filterText = filter;
getViewer().setInput(filter);
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
@Override
public void setSelection(ISelection selection) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection, reveal);
}
};
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
table = (_tableViewer = filterTree.getViewer()).getTable();
defaultMessage = rendererProp.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
if (defaultMessage != null)
filterTree.getFilterControl().setMessage(defaultMessage);
} else {
filterTree = null;
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame()) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
if (displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0)
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
table = new Table(group, style);
} else {
table = new Table(_mainPane, style);
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
table = new Table(_mainPane, style);
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
_tableViewer = new TableViewer(table) {
@Override
public void setSelection(ISelection selection) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection)
selection = new StructuredSelection();
super.setSelection(selection, reveal);
}
};
}
table.setLinesVisible(false);
table.setHeaderVisible(false);
Control[] children = table.getChildren();
for (Control control : children) {
hookKeyListener(control);
}
hookKeyListener(table);
EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
ColumnViewerToolTipSupport.enableFor(_tableViewer);
final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
final Map<ColumnLabelProvider, EJScreenItemProperties> nodeTextProvidersMap = new HashMap<ColumnLabelProvider, EJScreenItemProperties>();
for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
for (EJScreenItemProperties screenItemProperties : itemProperties) {
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
ColumnLabelProvider screenItem = createScreenItem(factory, mainScreenItemProperties);
if (screenItem != null) {
nodeTextProviders.add(screenItem);
nodeTextProvidersMap.put(screenItem, screenItemProperties);
}
}
}
if (!nodeTextProviders.isEmpty()) {
table.setData(EJ_RWT.MARKUP_ENABLED, Boolean.TRUE);
int height = rendererProp.getIntProperty(EJRWTListRecordBlockDefinitionProperties.ROW_HEIGHT, -1);
if (height == -1 && nodeTextProviders.size() > 1) {
table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, Integer.valueOf(nodeTextProviders.size() * 20));
} else if (height > 0) {
table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, Integer.valueOf(height));
}
// add double click action
final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTListRecordBlockDefinitionProperties.CLICK_ACTION_COMMAND);
final boolean hasAction = doubleClickActionCommand != null && doubleClickActionCommand.length() != 0;
if (hasAction) {
_tableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent arg0) {
_block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
}
});
}
final TableViewerColumn dataColumn = factory.createColumn("HTML", 500, new ColumnLabelProvider() {
public String toHex(int r, int g, int b) {
return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
}
private String toBrowserHexValue(int number) {
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
while (builder.length() < 2) {
builder.append("0");
}
return builder.toString().toUpperCase();
}
@Override
public String getText(Object element) {
StringBuilder builder = new StringBuilder();
boolean addBr = false;
for (ColumnLabelProvider labelProvider : nodeTextProviders) {
if (addBr) {
builder.append("<br/>");
}
boolean added = false;
EJScreenItemProperties item = nodeTextProvidersMap.get(labelProvider);
if (item != null && item.getLabel() != null && item.getLabel().trim().length() > 0) {
builder.append(item.getLabel());
builder.append(" : ");
added = true;
}
Image image = labelProvider.getImage(element);
if (image != null) {
String imagePath = ImageFactory.getImagePath(image);
if (imagePath != null) {
builder.append("<img src=\"");
builder.append(imagePath);
Rectangle bounds = image.getBounds();
builder.append("\" style=\"vertical-align:middle;\" ");
builder.append(" width=\"");
builder.append(bounds.width);
builder.append("\" ");
builder.append(" height=\"");
builder.append(bounds.height);
builder.append("\"/>");
added = true;
}
}
String text = labelProvider.getText(element);
if (text != null && text.length() != 0) {
Font vaFont = labelProvider.getFont(element);
builder.append("<span style=\"");
if (vaFont != null && vaFont.getFontData().length > 0) {
FontData fontData = vaFont.getFontData()[0];
if ((fontData.getStyle() & SWT.BOLD) != 0) {
builder.append("font-weight:bold;");
}
if ((fontData.getStyle() & SWT.ITALIC) != 0) {
builder.append("font-style:italic;");
}
builder.append("font-size:");
builder.append(fontData.getHeight());
builder.append("px;");
builder.append("font-family:");
builder.append(fontData.getName().replace('"', ' '));
builder.append(";");
}
Color background = labelProvider.getBackground(element);
if (background != null) {
builder.append("background-color:");
builder.append(toHex(background.getRed(), background.getGreen(), background.getBlue()));
builder.append(";");
}
Color foreground = labelProvider.getForeground(element);
if (foreground != null) {
builder.append("color:");
builder.append(toHex(foreground.getRed(), foreground.getGreen(), foreground.getBlue()));
builder.append(";");
}
builder.append("\">");
builder.append(text);
builder.append("</span>");
added = true;
}
if (added) {
addBr = true;
}
}
return builder.toString();
}
});
if (hasAction) {
final Image arrow = EJRWTImageRetriever.get("icons/left-arrow.png");
final TableViewerColumn actionColumn = factory.createColumn("HTML-ACTION", 40, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return "";
}
@Override
public Image getImage(Object element) {
return arrow;
}
});
actionColumn.getColumn().setAlignment(SWT.RIGHT);
actionColumn.setEditingSupport(new EditingSupport(_tableViewer) {
protected void setValue(Object arg0, Object arg1) {
// ignore
}
protected Object getValue(Object arg0) {
// ignore
return null;
}
protected CellEditor getCellEditor(Object arg0) {
return new CellEditor() {
@Override
protected void doSetValue(Object arg0) {
// ignore
}
@Override
protected void doSetFocus() {
// ignore
}
@Override
protected Object doGetValue() {
// ignore
return null;
}
@Override
protected Control createControl(Composite parent) {
Label action = new Label(parent, SWT.NONE);
action.setImage(arrow);
return action;
}
};
}
protected boolean canEdit(Object arg0) {
_block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
return false;
}
});
}
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
int offset = hasAction ? 50 : 10;
if (table.getSize().x > offset)
dataColumn.getColumn().setWidth(table.getSize().x - offset);
}
});
}
table.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
setHasFocus(false);
}
public void focusGained(FocusEvent arg0) {
setHasFocus(true);
}
});
// setHasFocus(true);
_mainPane.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl())
setHasFocus(true);
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl())
setHasFocus(true);
}
});
final EJBlockController blockController = _block;
_tableViewer.setContentProvider(filteredContentProvider = new FilteredContentProvider() {
boolean matchItem(EJDataRecord rec) {
if (filter != null && filter.trim().length() > 0) {
for (ColumnLabelProvider filterTextProvider : nodeTextProviders) {
String text = filterTextProvider.getText(rec);
if ((text != null) && text.toLowerCase().contains(filter.toLowerCase())) {
return true;
}
}
}
return false;
}
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
tableBaseRecords.clear();
if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
for (EJDataRecord record : _block.getBlock().getRecords()) {
if (matchItem(record))
tableBaseRecords.add(record);
}
} else {
filter = null;
if (filterTree != null)
filterTree.clearText();
tableBaseRecords.addAll(_block.getBlock().getRecords());
}
}
public void dispose() {
}
public Object[] getElements(Object arg0) {
return tableBaseRecords.toArray();
}
});
_tableViewer.setInput(new Object());
selectRow(0);
_tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent arg0) {
EJDataRecord focusedRecord = getFocusedRecord();
if (focusedRecord != null)
_block.newRecordInstance(focusedRecord);
notifyStatus();
}
});
}
use of org.eclipse.jface.viewers.EditingSupport in project egit by eclipse.
the class GitSynchronizeWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
for (IProject project : ROOT.getProjects()) {
RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
if (repositoryMapping == null)
continue;
Repository repo = repositoryMapping.getRepository();
Set<IProject> projects = resources.get(repo);
if (projects == null) {
projects = new HashSet<>();
resources.put(repo, projects);
}
projects.add(project);
}
treeViewer = new TreeViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
treeViewer.getTree().setLinesVisible(true);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TreeViewerColumn projectsColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
projectsColumn.getColumn().setText(UIText.GitBranchSynchronizeWizardPage_repository);
projectsColumn.getColumn().setImage(repositoryImage);
projectsColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Repository) {
Repository repo = (Repository) element;
// $NON-NLS-1$
String descr = "";
try {
// $NON-NLS-1$ //$NON-NLS-2$
descr += " [" + repo.getBranch() + "]";
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
}
Color decorationsColor = JFaceResources.getColorRegistry().get(JFacePreferences.DECORATIONS_COLOR);
String repoName = repo.getWorkTree().getName();
int repoNameLen = repoName.length();
StyleRange styleRange = new StyleRange(repoNameLen, repoNameLen + descr.length(), decorationsColor, null);
cell.setImage(repositoryImage);
cell.setText(repoName + descr);
cell.setStyleRanges(new StyleRange[] { styleRange });
}
super.update(cell);
}
});
TreeViewerColumn dstColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
dstColumn.getColumn().setText(UIText.GitBranchSynchronizeWizardPage_destination);
dstColumn.getColumn().setImage(branchImage);
dstColumn.getColumn().setWidth(200);
final ComboBoxCellEditor branchesEditor = new ComboBoxCellEditor(treeViewer.getTree(), new String[0]);
branchesEditor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION);
((CCombo) branchesEditor.getControl()).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CCombo combo = (CCombo) e.widget;
TreeSelection sel = (TreeSelection) treeViewer.getSelection();
int selectedIdx = combo.getSelectionIndex();
Repository repo = (Repository) sel.getFirstElement();
if (selectedIdx != -1) {
selectedBranches.put(repo, combo.getItem(selectedIdx));
setPageComplete(true);
} else {
selectedBranches.put(repo, null);
setPageComplete(false);
}
}
});
dstColumn.setEditingSupport(new EditingSupport(treeViewer) {
@Override
protected void setValue(Object element, Object value) {
int intValue = ((Integer) value).intValue();
if (intValue == -1)
return;
CCombo combo = (CCombo) branchesEditor.getControl();
String branch = combo.getItem(intValue);
selectedBranches.put((Repository) element, branch);
treeViewer.refresh(element, true);
validatePage();
}
@Override
protected Object getValue(Object element) {
String branch = selectedBranches.get(element);
CCombo combo = (CCombo) branchesEditor.getControl();
int index = branch == null ? 0 : combo.indexOf(branch);
return Integer.valueOf(index);
}
@Override
protected CellEditor getCellEditor(Object element) {
Repository repo = (Repository) element;
List<String> refs = new LinkedList<>(repo.getAllRefs().keySet());
List<Ref> additionalRefs;
try {
additionalRefs = repo.getRefDatabase().getAdditionalRefs();
} catch (IOException e) {
additionalRefs = null;
}
if (additionalRefs != null)
for (Ref ref : additionalRefs) refs.add(ref.getName());
Collections.sort(refs, CommonUtils.STRING_ASCENDING_COMPARATOR);
branchesEditor.setItems(refs.toArray(new String[refs.size()]));
return branchesEditor;
}
@Override
protected boolean canEdit(Object element) {
return true;
}
});
dstColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String branch = selectedBranches.get(element);
// $NON-NLS-1$
return branch == null ? "" : branch;
}
});
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// nothing to do
}
@Override
public void dispose() {
// nothing to do
}
@Override
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
});
List<Repository> repositoriesList = new ArrayList<>(resources.keySet());
Collections.sort(repositoriesList, new Comparator<Repository>() {
@Override
public int compare(Repository o1, Repository o2) {
String name1 = o1.getWorkTree().getName();
String name2 = o2.getWorkTree().getName();
return name1.compareToIgnoreCase(name2);
}
});
treeViewer.setInput(repositoriesList.toArray(new Repository[repositoriesList.size()]));
projectsColumn.getColumn().pack();
Composite buttonsComposite = new Composite(composite, SWT.NONE);
layout = new GridLayout(4, false);
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
buttonsComposite.setLayout(layout);
buttonsComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
final Button fetchChanges = new Button(buttonsComposite, SWT.CHECK);
fetchChanges.setText(UIText.GitBranchSynchronizeWizardPage_fetchChangesFromRemote);
fetchChanges.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
forceFetch = fetchChanges.getSelection();
}
});
fetchChanges.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
fetchChanges.setSelection(Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.SYNC_VIEW_FETCH_BEFORE_LAUNCH));
final Button includeLocal = new Button(buttonsComposite, SWT.CHECK);
includeLocal.setText(UIText.GitBranchSynchronizeWizardPage_includeUncommitedChanges);
includeLocal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
shouldIncludeLocal = includeLocal.getSelection();
}
});
includeLocal.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Dialog.applyDialogFont(composite);
setPageComplete(false);
setControl(composite);
}
use of org.eclipse.jface.viewers.EditingSupport in project egit by eclipse.
the class RefSpecPanel method createRemoveColumn.
private void createRemoveColumn(TableColumnLayout columnLayout) {
final TableViewerColumn column = createColumn(columnLayout, UIText.RefSpecPanel_columnRemove, COLUMN_REMOVE_WEIGHT, SWT.CENTER);
column.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
return imageRegistry.get(IMAGE_TRASH);
}
@Override
public String getToolTipText(Object element) {
return NLS.bind(UIText.RefSpecPanel_removeDescription, typeString());
}
});
column.setEditingSupport(new EditingSupport(tableViewer) {
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return removeSpecCellEditor;
}
@Override
protected Object getValue(Object element) {
return null;
}
@Override
protected void setValue(Object element, Object value) {
removeRefSpec((RefSpec) element);
}
});
}
Aggregations