use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class RepositoriesView method createPartControl.
@Override
public void createPartControl(final Composite parent) {
// CREATE CONTROLS
final StackLayout stackLayout = new StackLayout();
parent.setLayout(stackLayout);
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
Composite defaultParent = toolkit.createComposite(parent, SWT.NONE);
FillLayout fill = new FillLayout();
fill.marginHeight = 5;
fill.marginWidth = 5;
defaultParent.setLayout(fill);
if (!Central.hasWorkspaceDirectory()) {
FormText form = toolkit.createFormText(defaultParent, true);
form.setText("<form><p>No workspace configuration found. <a>Create a new Bnd workspace...</a></p></form>", true, false);
form.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
wizard.init(workbench, StructuredSelection.EMPTY);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
}
});
} else {
toolkit.createLabel(defaultParent, "Repositories are loading, please wait...");
}
stackLayout.topControl = defaultParent;
parent.layout();
final Composite mainPanel = new Composite(parent, SWT.NONE);
filterPanel = filterPart.createControl(mainPanel, 5, 5);
Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI);
filterPanel.setBackground(tree.getBackground());
viewer = new TreeViewer(tree);
contentProvider = new SearchableRepositoryTreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
super.inputChanged(viewer, oldInput, newInput);
if (newInput != null) {
stackLayout.topControl = mainPanel;
advancedSearchAction.setEnabled(true);
refreshAction.setEnabled(true);
collapseAllAction.setEnabled(true);
configureOfflineAction();
parent.layout();
}
}
};
viewer.setContentProvider(contentProvider);
ColumnViewerToolTipSupport.enableFor(viewer);
viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
getViewSite().setSelectionProvider(viewer);
Central.addRepositoriesViewer(viewer, RepositoriesView.this);
JpmPreferences jpmPrefs = new JpmPreferences();
final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL;
// LISTENERS
filterPart.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String filter = (String) event.getNewValue();
updatedFilter(filter);
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (target == null)
return false;
if (canDrop(target, transferType))
return true;
boolean valid = false;
if (target instanceof RepositoryPlugin) {
if (((RepositoryPlugin) target).canWrite()) {
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof IStructuredSelection) {
for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) {
valid = true;
break;
}
if (element instanceof IFile) {
valid = true;
break;
}
if (element instanceof IAdaptable) {
IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
if (file != null) {
valid = true;
break;
}
}
}
}
} else {
valid = true;
}
}
}
return valid;
}
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean performDrop(Object data) {
if (RepositoriesView.this.performDrop(getCurrentTarget(), getCurrentEvent().currentDataType, data)) {
viewer.refresh(getCurrentTarget(), true);
return true;
}
boolean copied = false;
if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) {
try {
URL url = new URL((String) URLTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType));
if (!url.getPath().endsWith(".jar")) {
String uris = url.toString();
if (uris.contains("#!/p/sha/")) {
MessageDialog.openWarning(null, "Dropped URL is a JPM Revision Identifier, not a JAR", "The dropped URL is a JPM identifier, can only be dropped on a JPM repository. You can also select the revision on JPM and drag the 'jar' link of the revision to any of the other repositories.");
return false;
}
}
File tmp = File.createTempFile("dwnl", ".jar");
try (HttpClient client = new HttpClient()) {
IO.copy(client.connect(url), tmp);
}
if (isJarFile(tmp)) {
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] { tmp });
} else {
tmp.delete();
MessageDialog.openWarning(null, "Unrecognized Artifact", "The dropped URL is not recognized as a remote JAR file: " + url.toString());
}
} catch (Exception e) {
return false;
}
} else if (data instanceof String[]) {
String[] paths = (String[]) data;
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
} else if (data instanceof IResource[]) {
IResource[] resources = (IResource[]) data;
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
} else if (data instanceof IStructuredSelection) {
File[] files = convertSelectionToFiles((IStructuredSelection) data);
if (files != null && files.length > 0)
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
}
return copied;
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter);
viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
boolean writableRepoSelected = false;
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object element = selection.getFirstElement();
if (element instanceof RepositoryPlugin) {
RepositoryPlugin repo = (RepositoryPlugin) element;
writableRepoSelected = repo.canWrite();
}
addBundlesAction.setEnabled(writableRepoSelected);
}
});
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent ev) {
Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (element instanceof ContinueSearchElement) {
try {
getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE);
} catch (PartInitException e) {
Plugin.getDefault().getLog().log(e.getStatus());
}
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (!event.getSelection().isEmpty()) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
final Object element = selection.getFirstElement();
if (element instanceof IAdaptable) {
final URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class);
if (uri == null && element instanceof RepositoryEntry) {
boolean download = MessageDialog.openQuestion(getSite().getShell(), "Repositories", "This repository entry is unable to be opened because it has not been downloaded. Download and open it now?");
if (download) {
final RepositoryEntry entry = (RepositoryEntry) element;
Job downloadJob = new Job("Downloading repository entry " + entry.getBsn()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final File repoFile = entry.getFile(true);
if (repoFile != null && repoFile.exists()) {
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
openURI(repoFile.toURI());
}
});
}
return Status.OK_STATUS;
}
};
downloadJob.setUser(true);
downloadJob.schedule();
}
} else if (uri != null) {
openURI(uri);
}
} else if (element instanceof ContinueSearchElement) {
ContinueSearchElement searchElement = (ContinueSearchElement) element;
try {
JpmPreferences jpmPrefs = new JpmPreferences();
if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
URI browseUrl = searchElement.browse();
getViewSite().getWorkbenchWindow().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(browseUrl.toURL());
} else
getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException e) {
Plugin.getDefault().getLog().log(e.getStatus());
} catch (Exception e) {
Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load repository browser view", e));
}
} else if (element instanceof RepositoryPlugin) {
viewer.setExpandedState(element, !viewer.getExpandedState(element));
}
}
}
});
createContextMenu();
// LAYOUT
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
mainPanel.setLayout(layout);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
// Toolbar
createActions();
fillToolBar(getViewSite().getActionBars().getToolBarManager());
prefs.addPropertyChangeListener(workspaceOfflineListener);
// synthenic call to "refresh" so that we can get the repositories to show up in the UI
new WorkspaceJob("Load repositories") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
Central.refreshPlugins();
} catch (Exception e) {
// ignore errors there may be no workspace yet
}
return Status.OK_STATUS;
}
}.schedule();
IActionBars actionBars = getViewSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
}
use of org.eclipse.core.runtime.IAdaptable in project che by eclipse.
the class SearchResultUpdater method elementChanged.
public void elementChanged(ElementChangedEvent event) {
//long t0= System.currentTimeMillis();
IJavaElementDelta delta = event.getDelta();
Set<IAdaptable> removedElements = new HashSet<IAdaptable>();
Set<IAdaptable> potentiallyRemovedElements = new HashSet<IAdaptable>();
collectRemoved(potentiallyRemovedElements, removedElements, delta);
if (removedElements.size() > 0)
handleRemoved(removedElements);
if (potentiallyRemovedElements.size() > 0)
handleRemoved(potentiallyRemovedElements);
//System.out.println(this+"handled delta in: "+(System.currentTimeMillis()-t0));
}
use of org.eclipse.core.runtime.IAdaptable in project che by eclipse.
the class JDTRefactoringDescriptorComment method initializeInferredSettings.
/**
* Initializes the inferred settings.
*
* @param object
* the refactoring object
*/
private void initializeInferredSettings(final Object object) {
if (object instanceof INameUpdating) {
final INameUpdating updating = (INameUpdating) object;
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(updating.getElements()[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
try {
final Object element = updating.getNewElement();
if (element != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED)));
else {
final String newLabel = BasicElementLabels.getJavaElementName(updating.getCurrentElementName());
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, newLabel));
}
} catch (CoreException exception) {
JavaPlugin.log(exception);
}
} else if (object instanceof RefactoringProcessor) {
final RefactoringProcessor processor = (RefactoringProcessor) object;
final Object[] elements = processor.getElements();
if (elements != null) {
if (elements.length == 1 && elements[0] != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
else if (elements.length > 1) {
final StringBuffer buffer = new StringBuffer(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
for (int index = 0; index < elements.length; index++) {
if (elements[index] != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
}
}
fSettings.add(buffer.toString());
}
}
} else if (object instanceof IReorgPolicy) {
final IReorgPolicy policy = (IReorgPolicy) object;
Object destination = policy.getJavaElementDestination();
if (destination != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
else {
destination = policy.getResourceDestination();
if (destination != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
}
final List<IAdaptable> list = new ArrayList<IAdaptable>();
list.addAll(Arrays.asList(policy.getJavaElements()));
list.addAll(Arrays.asList(policy.getResources()));
final Object[] elements = list.toArray();
if (elements != null) {
if (elements.length == 1 && elements[0] != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
else if (elements.length > 1) {
final StringBuffer buffer = new StringBuffer(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
for (int index = 0; index < elements.length; index++) {
if (elements[index] != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
}
}
fSettings.add(buffer.toString());
}
}
if (object instanceof IMovePolicy) {
final IMovePolicy extended = (IMovePolicy) object;
if (extended.isTextualMove())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptorComment_textual_move_only);
}
}
if (object instanceof IReferenceUpdating) {
final IReferenceUpdating updating = (IReferenceUpdating) object;
if (updating.getUpdateReferences())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references);
}
if (object instanceof ISimilarDeclarationUpdating) {
final ISimilarDeclarationUpdating updating = (ISimilarDeclarationUpdating) object;
if (updating.canEnableSimilarDeclarationUpdating() && updating.getUpdateSimilarDeclarations()) {
final int strategy = updating.getMatchStrategy();
if (strategy == RenamingNameSuggestor.STRATEGY_EXACT)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar);
else if (strategy == RenamingNameSuggestor.STRATEGY_EMBEDDED)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_embedded);
else if (strategy == RenamingNameSuggestor.STRATEGY_SUFFIX)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_suffix);
}
}
if (object instanceof IQualifiedNameUpdating) {
final IQualifiedNameUpdating updating = (IQualifiedNameUpdating) object;
if (updating.canEnableQualifiedNameUpdating() && updating.getUpdateQualifiedNames()) {
final String patterns = updating.getFilePatterns();
if (//$NON-NLS-1$
patterns != null && !"".equals(patterns))
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names_pattern, BasicElementLabels.getFilePattern(patterns.trim())));
else
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names);
}
}
if (object instanceof ITextUpdating) {
final ITextUpdating updating = (ITextUpdating) object;
if (updating.canEnableTextUpdating())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_textual_occurrences);
}
if (object instanceof IDelegateUpdating) {
final IDelegateUpdating updating = (IDelegateUpdating) object;
if (updating.canEnableDelegateUpdating() && updating.getDelegateUpdating()) {
if (updating.getDeprecateDelegates())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original_deprecated);
else
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original);
}
}
}
use of org.eclipse.core.runtime.IAdaptable in project flux by eclipse.
the class SyncConnectHandler method getSelectedProjects.
protected IProject[] getSelectedProjects(ISelection selection) {
List<IProject> selectedProjects = new ArrayList<IProject>();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object[] selectedObjects = structuredSelection.toArray();
for (int i = 0; i < selectedObjects.length; i++) {
if (selectedObjects[i] instanceof IAdaptable) {
IProject project = (IProject) ((IAdaptable) selectedObjects[i]).getAdapter(IProject.class);
if (project != null) {
selectedProjects.add(project);
}
}
}
}
return (IProject[]) selectedProjects.toArray(new IProject[selectedProjects.size()]);
}
use of org.eclipse.core.runtime.IAdaptable in project translationstudio8 by heartsome.
the class ResourceMgmtActionProvider method fillContextMenu.
/**
* Adds the build, open project, close project and refresh resource actions to the context menu.
* <p>
* The following conditions apply: build-only projects selected, auto build disabled, at least one builder present
* open project-only projects selected, at least one closed project close project-only projects selected, at least
* one open project refresh-no closed project selected
* </p>
* <p>
* Both the open project and close project action may be on the menu at the same time.
* </p>
* <p>
* No disabled action should be on the context menu.
* </p>
* @param menu
* context menu to add actions to
*/
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
boolean isProjectSelection = true;
boolean hasOpenProjects = false;
boolean hasClosedProjects = false;
// false if any project is closed or does not
boolean hasBuilder = true;
// have builder
Iterator resources = selection.iterator();
while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
Object next = resources.next();
IProject project = null;
if (next instanceof IProject) {
project = (IProject) next;
} else if (next instanceof IAdaptable) {
project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
}
if (project == null) {
isProjectSelection = false;
continue;
}
if (project.isOpen()) {
hasOpenProjects = true;
if (hasBuilder && !hasBuilder(project)) {
hasBuilder = false;
}
} else {
hasClosedProjects = true;
hasBuilder = false;
}
}
// }
if (isProjectSelection) {
if (hasClosedProjects) {
openProjectAction.selectionChanged(selection);
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, openProjectAction);
}
if (hasOpenProjects) {
closeProjectAction.selectionChanged(selection);
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, closeProjectAction);
// closeUnrelatedProjectsAction.selectionChanged(selection);
// menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, closeUnrelatedProjectsAction);
}
}
if (!hasClosedProjects) {
refreshAction.selectionChanged(selection);
refreshAction.setEnabled(!selection.isEmpty());
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, refreshAction);
}
}
Aggregations