boolean isPersistable() { if (editorInput != null) { IPersistableElement persistable = editorInput.getPersistable(); return persistable != null; } return memento != null; }
@Override public String getFactoryId() { IEditorPart editor = getEditor(false); if (editor == null) { if (input == null) { return factoryId; } IPersistableElement persistable = input.getPersistable(); return persistable == null ? null : persistable.getFactoryId(); } IPersistableElement persistable = editor.getEditorInput().getPersistable(); return persistable == null ? null : persistable.getFactoryId(); }
/** * Method writeEditorInput. * @param dataOut * @param editorInputData */ private void writeEditorInput(DataOutputStream dataOut, EditorInputData editorInputData) throws IOException { //write the id of the editor dataOut.writeUTF(editorInputData.editorId); //write the information needed to recreate the editor input if (editorInputData.input != null) { // Capture the editor information XMLMemento memento = XMLMemento.createWriteRoot("IEditorInput");//$NON-NLS-1$ IPersistableElement element = editorInputData.input .getPersistable(); if (element != null) { //get the IEditorInput to save its state element.saveState(memento); //convert memento to String StringWriter writer = new StringWriter(); memento.save(writer); writer.close(); //write the factor ID and state information dataOut.writeUTF(element.getFactoryId()); dataOut.writeUTF(writer.toString()); } } }
/** * Returns whether this history item can be saved. */ public boolean canSave() { return !isRestored() || (getInput() != null && getInput().getPersistable() != null); }
public static void testEditorInput(IEditorInput input) throws Exception { input.getAdapter(Object.class); // Don't test input.getImageDescriptor() -- the workbench never uses that // method and most editor inputs would fail the test. It should really be // deprecated. Assert.isNotNull(input.getName(), "The editor input must have a non-null name"); //$NON-NLS-1$ Assert.isNotNull(input.getToolTipText(), "The editor input must have a non-null tool tip"); //$NON-NLS-1$ // Persistable element may be null IPersistableElement persistableElement = input.getPersistable(); if (persistableElement != null) { Assert .isNotNull(persistableElement.getFactoryId(), "The persistable element for the editor input must have a non-null factory id"); //$NON-NLS-1$ } }
@Override protected void createFormContent(IManagedForm managedForm) { ScrolledForm form = managedForm.getForm(); Composite comp = managedForm.getToolkit().createComposite(form); comp.setLayout(new GridLayout()); IPersistableElement persistable = getEditorInput().getPersistable(); String text; if (persistable instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) persistable).getFile(); text = NLS.bind(PDEUIMessages.MissingResourcePage_unableToOpenFull, new String[] {PDEUIMessages.MissingResourcePage_unableToOpen, file.getProjectRelativePath().toString(), file.getProject().getName()}); } else text = PDEUIMessages.MissingResourcePage_unableToOpen; form.setText(text); comp.setLayoutData(new GridData(GridData.FILL_BOTH)); } }
/** * Returns the factory id of this item, either from the input if restored, * otherwise from the memento. * Returns <code>null</code> if there is no factory id. */ public String getFactoryId() { if (isRestored()) { if (input != null) { IPersistableElement persistable = input.getPersistable(); if (persistable != null) { return persistable.getFactoryId(); } } } else if (memento != null) { return memento.getString(IWorkbenchConstants.TAG_FACTORY_ID); } return null; }
void saveState(IMemento mem) { if (editorInput != null) { IPersistableElement persistable = editorInput.getPersistable(); mem.putString(IWorkbenchConstants.TAG_ID, editorID); mem.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable .getFactoryId()); persistable.saveState(mem); } else if (memento != null) { mem.putMemento(memento); } } }
/** * Returns whether this item matches the given editor input. */ public boolean matches(IEditorInput input) { if (isRestored()) { return input.equals(getInput()); } // if not restored, compare name, tool tip text and factory id, // avoiding as much work as possible if (!getName().equals(input.getName())) { return false; } if (!getToolTipText().equals(input.getToolTipText())) { return false; } IPersistableElement persistable = input.getPersistable(); String inputId = persistable == null ? null : persistable .getFactoryId(); String myId = getFactoryId(); return myId == null ? inputId == null : myId.equals(inputId); }
@Override public void dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<>(); ISelection selection= fProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) selection; for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) { Object element= iter.next(); IEditorInput editorInput= EditorUtility.getEditorInput(element); if (editorInput != null && editorInput.getPersistable() != null) { try { String editorId= EditorUtility.getEditorID(editorInput); // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..): IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc= editorReg.findEditor(editorId); if (editorDesc != null && !editorDesc.isOpenExternal()) { fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput)); } } catch (PartInitException e) { JavaPlugin.log(e); } } } } event.doit= fEditorInputDatas.size() > 0; }
try { String name = input.getName(); IPersistableElement persistable = input.getPersistable(); if (name == null || persistable == null) { return;
@Override public void dragStart(DragSourceEvent event) { fEditorInputDatas= new ArrayList<>(); ISelection selection= fProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) selection; for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) { Object element= iter.next(); IEditorInput editorInput= EditorUtility.getEditorInput(element); if (editorInput != null && editorInput.getPersistable() != null) { try { String editorId= EditorUtility.getEditorID(editorInput); // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..): IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor editorDesc= editorReg.findEditor(editorId); if (editorDesc != null && !editorDesc.isOpenExternal()) { fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput)); } } catch (PartInitException e) { JavaPlugin.log(e); } } } } event.doit= fEditorInputDatas.size() > 0; }
void handlePartClosed() { if (!isPersistable()) { return; } if (memento == null) { IPersistableElement persistable = editorInput.getPersistable(); memento = XMLMemento .createWriteRoot(IWorkbenchConstants.TAG_EDITOR); memento.putString(IWorkbenchConstants.TAG_ID, editorID); memento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable .getFactoryId()); persistable.saveState(memento); } editorID = null; editorInput = null; }
IPersistableElement persistable = input.getPersistable(); if (persistable == null) { return null;
} else if (input != null) { IPersistableElement persistable = input.getPersistable(); if (persistable != null) {
inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID, curInput.getPersistable() .getFactoryId()); inputMem.putString(IWorkbenchConstants.TAG_PATH, curInput.getName());