use of org.eclipse.jface.viewers.StructuredViewer in project translationstudio8 by heartsome.
the class ResourceExtensionContentProvider method processDelta.
/**
* Process a resource delta. Add any runnables
*/
private void processDelta(IResourceDelta delta, Collection runnables) {
//he widget may have been destroyed
// by the time this is run. Check for this and do nothing if so.
Control ctrl = viewer.getControl();
if (ctrl == null || ctrl.isDisposed()) {
return;
}
// Get the affected resource
final IResource resource = delta.getResource();
// If any children have changed type, just do a full refresh of this
// parent,
// since a simple update on such children won't work,
// and trying to map the change to a remove and add is too dicey.
// The case is: folder A renamed to existing file B, answering yes to
// overwrite B.
IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED);
for (int i = 0; i < affectedChildren.length; i++) {
if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) {
runnables.add(getRefreshRunnable(resource));
return;
}
}
// Check the flags for changes the Navigator cares about.
// See ResourceLabelProvider for the aspects it cares about.
// Notice we don't care about F_CONTENT or F_MARKERS currently.
int changeFlags = delta.getFlags();
if ((changeFlags & (IResourceDelta.OPEN | IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) {
// Runnable updateRunnable = new Runnable(){
// public void run() {
// ((StructuredViewer) viewer).update(resource, null);
// }
// };
// runnables.add(updateRunnable);
/* support the Closed Projects filter;
* when a project is closed, it may need to be removed from the view.
*/
runnables.add(getRefreshRunnable(resource.getParent()));
}
// Replacing a resource may affect its label and its children
if ((changeFlags & IResourceDelta.REPLACED) != 0) {
runnables.add(getRefreshRunnable(resource));
return;
}
// Handle changed children .
for (int i = 0; i < affectedChildren.length; i++) {
processDelta(affectedChildren[i], runnables);
}
// @issue several problems here:
// - should process removals before additions, to avoid multiple equal
// elements in viewer
// - Kim: processing removals before additions was the indirect cause of
// 44081 and its varients
// - Nick: no delta should have an add and a remove on the same element,
// so processing adds first is probably OK
// - using setRedraw will cause extra flashiness
// - setRedraw is used even for simple changes
// - to avoid seeing a rename in two stages, should turn redraw on/off
// around combined removal and addition
// - Kim: done, and only in the case of a rename (both remove and add
// changes in one delta).
IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED);
IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED);
if (addedChildren.length == 0 && removedChildren.length == 0) {
return;
}
final Object[] addedObjects;
final Object[] removedObjects;
// Process additions before removals as to not cause selection
// preservation prior to new objects being added
// Handle added children. Issue one update for all insertions.
int numMovedFrom = 0;
int numMovedTo = 0;
if (addedChildren.length > 0) {
addedObjects = new Object[addedChildren.length];
for (int i = 0; i < addedChildren.length; i++) {
addedObjects[i] = addedChildren[i].getResource();
if ((addedChildren[i].getFlags() & IResourceDelta.MOVED_FROM) != 0) {
++numMovedFrom;
}
}
} else {
addedObjects = new Object[0];
}
// Handle removed children. Issue one update for all removals.
if (removedChildren.length > 0) {
removedObjects = new Object[removedChildren.length];
for (int i = 0; i < removedChildren.length; i++) {
removedObjects[i] = removedChildren[i].getResource();
if ((removedChildren[i].getFlags() & IResourceDelta.MOVED_TO) != 0) {
++numMovedTo;
}
}
} else {
removedObjects = new Object[0];
}
// heuristic test for items moving within same folder (i.e. renames)
final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0;
Runnable addAndRemove = new Runnable() {
public void run() {
if (viewer instanceof AbstractTreeViewer) {
AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer;
// rename case)
if (hasRename) {
treeViewer.getControl().setRedraw(false);
}
try {
if (addedObjects.length > 0) {
treeViewer.add(resource, addedObjects);
}
if (removedObjects.length > 0) {
treeViewer.remove(removedObjects);
}
} finally {
if (hasRename) {
treeViewer.getControl().setRedraw(true);
}
}
} else {
((StructuredViewer) viewer).refresh(resource);
}
}
};
runnables.add(addAndRemove);
}
use of org.eclipse.jface.viewers.StructuredViewer in project translationstudio8 by heartsome.
the class WorkingSetSorter method compare.
public int compare(Viewer viewer, Object e1, Object e2) {
if (viewer instanceof StructuredViewer) {
ILabelProvider labelProvider = (ILabelProvider) ((StructuredViewer) viewer).getLabelProvider();
String text1 = labelProvider.getText(e1);
String text2 = labelProvider.getText(e2);
if (text1 != null) {
return text1.compareTo(text2);
}
}
return -1;
}
use of org.eclipse.jface.viewers.StructuredViewer in project translationstudio8 by heartsome.
the class ResourceMgmtActionProvider method makeActions.
protected void makeActions() {
IShellProvider sp = new IShellProvider() {
public Shell getShell() {
return shell;
}
};
openProjectAction = new OpenResourceAction(sp);
openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);
closeProjectAction = new CloseResourceAction(sp);
closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
//
// closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
// closeUnrelatedProjectsAction.setText("关闭无关的项目");
refreshAction = new RefreshAction(sp) {
public void run() {
final IStatus[] errorStatus = new IStatus[1];
errorStatus[0] = Status.OK_STATUS;
final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
WorkspaceJob job = new //$NON-NLS-1$
WorkspaceJob(//$NON-NLS-1$
"refresh") {
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
op.run(monitor);
if (shell != null && !shell.isDisposed()) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
StructuredViewer viewer = getActionSite().getStructuredViewer();
if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
viewer.refresh();
}
}
});
}
} catch (InvocationTargetException e) {
String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle, getClass().getName(), e.getTargetException());
throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e.getTargetException()));
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
return errorStatus[0];
}
};
ISchedulingRule rule = op.getRule();
if (rule != null) {
job.setRule(rule);
}
job.setUser(true);
job.schedule();
}
};
refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
//$NON-NLS-1$
refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));
//$NON-NLS-1$
refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));
refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
if (getContext() == null) {
refreshAction.setEnabled(false);
} else {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
refreshAction.selectionChanged(selection);
refreshAction.setEnabled(!selection.isEmpty());
}
// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
use of org.eclipse.jface.viewers.StructuredViewer in project AutoRefactor by JnRouvignac.
the class ChooseRefactoringWizardPage method createSelectAllCheckbox.
private void createSelectAllCheckbox(Composite parent) {
selectAllVisibleCheckbox = new Button(parent, SWT.CHECK);
selectAllVisibleCheckbox.setText("Toggle all the visible refactorings");
selectAllVisibleCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
final Object[] visibleElements = filter(tableViewer, tableViewer.getInput());
for (Object element : visibleElements) {
setChecked(element, selectAllVisibleCheckbox.getSelection());
}
}
private Object[] filter(StructuredViewer viewer, Object input) {
try {
final Class<StructuredViewer> clazz = StructuredViewer.class;
Method m = clazz.getDeclaredMethod("filter", Object[].class);
m.setAccessible(true);
return (Object[]) m.invoke(viewer, (Object) ((List<?>) input).toArray());
} catch (Exception e) {
throw new UnhandledException(null, e);
}
}
});
}
use of org.eclipse.jface.viewers.StructuredViewer in project tdi-studio-se by Talend.
the class CreateDiagramAction method setRepositoryNode.
private void setRepositoryNode(Properties params) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == workbenchWindow) {
return;
}
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (null == workbenchPage) {
return;
}
IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
// show di perspective
try {
workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
workbenchPage = workbenchWindow.getActivePage();
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return;
}
}
// bug 16594
IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
if (view != null) {
Object type = params.get("type");
if (ERepositoryObjectType.BUSINESS_PROCESS != null && ERepositoryObjectType.BUSINESS_PROCESS.name().equals(type)) {
RepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ERepositoryObjectType.BUSINESS_PROCESS);
final StructuredViewer viewer = view.getViewer();
if (viewer instanceof TreeViewer) {
((TreeViewer) viewer).expandToLevel(processNode, 1);
}
this.repositoryNode = processNode;
}
}
}
Aggregations