use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.
the class EditWorkflowDefinitionAction method perform.
@Override
public void perform(Object entry) {
if (entry instanceof WorkflowDefinitionEntry) {
WorkflowDefinitionEntry workflowEntry = (WorkflowDefinitionEntry) entry;
IWorkbench workBench = PlatformUI.getWorkbench();
IWorkbenchWindow wbWindow = workBench.getActiveWorkbenchWindow();
IWorkbenchPage page = wbWindow.getActivePage();
IEditorPart[] dirtyEditors = page.getDirtyEditors();
for (IEditorPart dirtyEditor : dirtyEditors) {
IEditorInput editorInput = dirtyEditor.getEditorInput();
if (editorInput instanceof WorkflowDefinitionEditorInput) {
WorkflowDefinitionEditorInput dirtyWorkflowEditorInput = (WorkflowDefinitionEditorInput) editorInput;
boolean opened = dirtyWorkflowEditorInput.getName().contains(workflowEntry.getName());
if (opened) {
IEditorSite editorSite = dirtyEditor.getEditorSite();
boolean saveOld = MessageDialog.openQuestion(editorSite.getShell(), "Save " + dirtyWorkflowEditorInput.getName(), "Do you want to save contents of this editor?");
page.closeEditor(dirtyEditor, saveOld);
}
}
}
try {
WorkflowDefinitionEditorInput editorInput = new WorkflowDefinitionEditorInput(workflowEntry);
IEditorPart editor = page.openEditor(editorInput, WorkflowDefinitionEditor.EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT);
editor.addPropertyListener(new IPropertyListener() {
public void propertyChanged(Object source, int propId) {
if (source.equals(editor) && (propId == WorkflowDefinitionEditor.propUpdateVersion)) {
workflowEntry.getParent().clearCache();
((CommonViewer) EditWorkflowDefinitionAction.this.getSelectionProvider()).refresh(true);
}
}
});
} catch (PartInitException pie) {
KaleoUI.logError("Error opening kaleo workflow editor.", pie);
}
}
}
use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.
the class EditorSiteAdapterService method convert.
@Override
public <A> A convert(Object object, Class<A> adapterType) {
A retval = null;
if (IEditorSite.class.equals(adapterType)) {
SapphirePart sapphirePart = context(SapphirePart.class);
Element localElement = sapphirePart.getLocalModelElement();
ITextEditor editor = localElement.adapt(ITextEditor.class);
IWorkbenchPartSite editorSite = editor.getSite();
if (editorSite instanceof IEditorSite) {
retval = adapterType.cast(editorSite);
}
}
return retval;
}
use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.
the class ScriptPropertyEditorRenderer method createContents.
@Override
protected void createContents(Composite parent) {
PropertyEditorPart part = part();
Element element = part.getLocalModelElement();
ValueProperty property = part.property().nearest(ValueProperty.class);
CreateMainCompositeDelegate createMainCompositeDelegate = new CreateMainCompositeDelegate(part) {
@Override
public boolean canScaleVertically() {
return true;
}
};
Composite codeEditorParent = createMainComposite(parent, createMainCompositeDelegate);
// context.adapt( codeEditorParent );
int codeEditorParentColumns = 1;
SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
if (actionsToolBarNeeded) {
codeEditorParentColumns++;
}
codeEditorParent.setLayout(glayout(codeEditorParentColumns, 0, 0, 0, 0));
Composite nestedComposite = new Composite(codeEditorParent, SWT.NONE);
nestedComposite.setLayoutData(gdfill());
// nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
addControl(nestedComposite);
PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
decorator.addEditorControl(nestedComposite);
ScriptPropertyEditorInput editorInput = new ScriptPropertyEditorInput(element, property);
List<Control> relatedControls = new ArrayList<>();
try {
IEditorSite editorSite = part().adapt(IEditorSite.class);
_editorPart = createEditorPart(editorInput, editorSite);
_editorPart.createPartControl(nestedComposite);
Control editorControl = _editorPart.getAdapter(Control.class);
// need to find the first child of nestedComposite to relayout
// editor control
Composite editorControlParent = null;
Control control = editorControl;
while ((editorControlParent == null) && (control != null) && !nestedComposite.equals(control.getParent())) {
control = control.getParent();
}
nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
control.setLayoutData(gdfill());
decorator.addEditorControl(editorControl, true);
editorControl.setData(RELATED_CONTROLS, relatedControls);
} catch (Exception e) {
KaleoUI.logError(e);
}
if (actionsToolBarNeeded) {
ToolBar toolbar = new ToolBar(codeEditorParent, SWT.FLAT | SWT.HORIZONTAL);
toolbar.setLayoutData(gdvfill());
toolBarActionsPresentation.setToolBar(toolbar);
toolBarActionsPresentation.render();
addControl(toolbar);
decorator.addEditorControl(toolbar);
relatedControls.add(toolbar);
}
List<Class<?>> listenerClasses = part.getRenderingHint(PropertyEditorDef.HINT_LISTENERS, Collections.<Class<?>>emptyList());
List<ValuePropertyEditorListener> listeners = new ArrayList<>();
if (ListUtil.isNotEmpty(listenerClasses)) {
for (Class<?> cl : listenerClasses) {
try {
ValuePropertyEditorListener listener = (ValuePropertyEditorListener) cl.newInstance();
listener.initialize(this);
listeners.add(listener);
} catch (Exception e) {
KaleoUI.logError(e);
}
}
}
ITextEditor textEditor = null;
if (_editorPart instanceof ITextEditor) {
textEditor = (ITextEditor) _editorPart;
} else {
ITextEditor textEdit = _editorPart.getAdapter(ITextEditor.class);
textEditor = textEdit;
}
addControl((Control) textEditor.getAdapter(Control.class));
IDocumentListener documentListener = new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
Value<Object> elementProperty = element.property(property);
elementProperty.write(event.getDocument().get());
if (ListUtil.isNotEmpty(listeners)) {
for (ValuePropertyEditorListener listener : listeners) {
try {
listener.handleValueChanged();
} catch (Exception e) {
KaleoUI.logError(e);
}
}
}
}
};
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
IDocument document = documentProvider.getDocument(_editorPart.getEditorInput());
document.addDocumentListener(documentListener);
}
use of org.eclipse.ui.IEditorSite in project webtools.sourceediting by eclipse.
the class AddImportHandler method execute.
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IEditorSite site = HandlerUtil.getActiveEditor(event).getEditorSite();
final ISelectionProvider provider = site.getSelectionProvider();
final ISelection selection = provider != null ? provider.getSelection() : null;
if (selection instanceof IStructuredSelection && selection instanceof ITextSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
final int offset = ((ITextSelection) selection).getOffset();
final Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IDOMNode) {
final IDOMModel model = ((IDOMNode) firstElement).getModel();
INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
translation.reconcileCompilationUnit();
final ICompilationUnit cu = translation.getCompilationUnit();
CompilationUnit astRoot = SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_YES, null);
if (astRoot != null) {
final ASTNode node = NodeFinder.perform(astRoot, translation.getJavaOffset(offset), 0);
if (node != null) {
SimpleName name = null;
if (node.getNodeType() == ASTNode.SIMPLE_NAME) {
name = (SimpleName) node;
} else if (node.getNodeType() == ASTNode.QUALIFIED_NAME) {
name = ((QualifiedName) node).getName();
}
if (name != null) {
IBinding binding = name.resolveBinding();
if (binding instanceof ITypeBinding && (binding.getJavaElement() == null || !binding.getJavaElement().exists())) {
// Look it up!
ITypeBinding typeBinding = (ITypeBinding) binding;
final IImportContainer importContainer = cu.getImportContainer();
if (!importContainer.getImport(typeBinding.getQualifiedName()).exists()) {
final List typesFound = new ArrayList();
final TypeNameMatchRequestor collector = new TypeNameMatcher(typesFound);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { cu.getJavaProject() });
final int mode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
try {
new SearchEngine().searchAllTypeNames(null, mode, name.getIdentifier().toCharArray(), mode, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
final int length = typesFound.size();
final List elements = new ArrayList();
for (int i = 0; i < length; i++) {
final TypeNameMatch match = (TypeNameMatch) typesFound.get(i);
final int modifiers = match.getModifiers();
if (!Flags.isPrivate(modifiers) && !Flags.isPackageDefault(modifiers)) {
elements.add(match);
}
}
TypeNameMatch match = null;
// If there's only one match, insert it; otherwise, open the dialog to choose from the list
if (elements.size() == 1) {
match = (TypeNameMatch) elements.get(0);
} else if (elements.size() > 1) {
ElementListSelectionDialog dialog = new ElementListSelectionDialog(site.getShell(), LABEL_PROVIDER);
dialog.setElements(elements.toArray(new TypeNameMatch[elements.size()]));
dialog.setTitle(JSPUIMessages.AddImportHandler_title);
dialog.setMessage(JSPUIMessages.AddImportHandler_label);
if (dialog.open() == Window.OK) {
final Object result = dialog.getFirstResult();
if (result instanceof TypeNameMatch) {
match = (TypeNameMatch) result;
}
}
}
addImport(match, model.getStructuredDocument());
} catch (JavaModelException e) {
// $NON-NLS-1$
Logger.logException("Exception while determining import.", e);
}
}
}
}
}
}
}
}
}
return null;
}
use of org.eclipse.ui.IEditorSite in project webtools.sourceediting by eclipse.
the class XSDMultiPageEditorContributor method setActivePage.
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
boolean isSource = false;
if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
isSource = true;
zoomInRetargetAction.setEnabled(false);
zoomOutRetargetAction.setEnabled(false);
captureScreenAction.setEnabled(false);
activateSourcePage(activeEditorPart, true);
} else {
activateSourcePage(xsdEditor, false);
if (part instanceof InternalXSDMultiPageEditor) {
xsdEditor = (InternalXSDMultiPageEditor) part;
}
if (xsdEditor != null) {
// cs: here's we ensure the UNDO and REDO actions are available when
// the design view is active
IWorkbenchPartSite site = xsdEditor.getSite();
if (site instanceof IEditorSite) {
ITextEditor textEditor = xsdEditor.getTextEditor();
IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
}
Object adapter = xsdEditor.getAdapter(ActionRegistry.class);
if (adapter instanceof ActionRegistry) {
ActionRegistry registry = (ActionRegistry) adapter;
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), registry.getAction(DeleteAction.ID));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_IN, registry.getAction(GEFActionConstants.ZOOM_IN));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_OUT, registry.getAction(GEFActionConstants.ZOOM_OUT));
actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), registry.getAction(ActionFactory.PRINT.getId()));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), registry.getAction(ActionFactory.SELECT_ALL.getId()));
zoomInRetargetAction.setEnabled(true);
zoomOutRetargetAction.setEnabled(true);
captureScreenAction.setEnabled(true);
}
}
}
if (actionBars != null) {
// update menu bar and tool bar
actionBars.updateActionBars();
}
if (zoomComboContributionItem != null) {
zoomComboContributionItem.setVisible(!isSource);
zoomComboContributionItem.update();
// Bug 254772 - parent contribution manager should not be null. We added this item already.
// Force the ToolBarManager to update/redraw the items
zoomComboContributionItem.getParent().update(true);
}
}
Aggregations