# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /data/work/src/netbeans-vcs # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: java.source/nbproject/project.xml --- java.source/nbproject/project.xml Base (BASE) +++ java.source/nbproject/project.xml Locally Modified (Based On LOCAL) @@ -85,6 +85,15 @@ + org.netbeans.core.multiview + + + + 1 + 1.24 + + + org.netbeans.libs.javacapi Index: java.source/src/org/netbeans/modules/java/Bundle.properties --- java.source/src/org/netbeans/modules/java/Bundle.properties Base (BASE) +++ java.source/src/org/netbeans/modules/java/Bundle.properties Locally Modified (Based On LOCAL) @@ -67,3 +67,5 @@ TP_NeedsCompileBadge=Needs to be compiled. TP_ExecutableBadge=Contains main class. TXT_OpenClassFile= Open Class File + +CTL_SourceTabCaption=&Source \ No newline at end of file Index: java.source/src/org/netbeans/modules/java/JavaDataObject.java --- java.source/src/org/netbeans/modules/java/JavaDataObject.java Base (BASE) +++ java.source/src/org/netbeans/modules/java/JavaDataObject.java Locally Modified (Based On LOCAL) @@ -48,11 +48,6 @@ import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Tree; import java.io.IOException; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.text.Document; -import javax.swing.text.EditorKit; -import javax.swing.text.StyledDocument; import org.netbeans.api.java.source.Task; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.JavaSource.Phase; @@ -60,6 +55,9 @@ import org.netbeans.api.java.source.TreeUtilities; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.api.java.source.TreeMaker; +import org.netbeans.core.api.multiview.MultiViews; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.core.spi.multiview.text.MultiViewEditorElement; import org.openide.cookies.EditCookie; import org.openide.cookies.EditorCookie; import org.openide.cookies.OpenCookie; @@ -81,6 +79,10 @@ import org.openide.text.DataEditorSupport; import org.openide.util.Lookup; import org.openide.windows.CloneableOpenSupport; +import org.openide.windows.CloneableTopComponent; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; public final class JavaDataObject extends MultiDataObject { @@ -199,6 +201,18 @@ } @Override + protected Pane createPane() { + CloneableTopComponent mvtc = MultiViews.createCloneableMultiView("text/x-java", getDataObject()); + + // dock into editor mode if possible. + Mode editorMode = WindowManager.getDefault().findMode(CloneableEditorSupport.EDITOR_MODE); + if (editorMode != null) { + editorMode.dockInto(mvtc); + } + return (CloneableEditorSupport.Pane)mvtc; + } + + @Override protected boolean asynchronousOpen() { return true; } @@ -208,6 +222,18 @@ } } + @MultiViewElement.Registration( + displayName="#CTL_SourceTabCaption", + iconBase="org/netbeans/modules/java/resources/class.gif", + persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED, + preferredID="java.source", + mimeType="text/x-java", + position=2000 + ) + public static MultiViewEditorElement createMultiViewEditorElement(Lookup context) { + return new MultiViewEditorElement(context); + } + private static final class JavaEditor extends CloneableEditor { private static final long serialVersionUID = -1; Index: localhistory/nbproject/project.xml --- localhistory/nbproject/project.xml Base (BASE) +++ localhistory/nbproject/project.xml Locally Modified (Based On LOCAL) @@ -15,6 +15,15 @@ + org.netbeans.core.multiview + + + + 1 + 1.24 + + + org.netbeans.modules.diff @@ -24,6 +33,15 @@ + org.netbeans.modules.editor.mimelookup + + + + 1 + 1.23 + + + org.netbeans.modules.options.api Index: localhistory/src/org/netbeans/modules/localhistory/ui/view/Bundle.properties --- localhistory/src/org/netbeans/modules/localhistory/ui/view/Bundle.properties Base (BASE) +++ localhistory/src/org/netbeans/modules/localhistory/ui/view/Bundle.properties Locally Modified (Based On LOCAL) @@ -56,3 +56,5 @@ LocalHistoryFolderPanel.jLabel1.text=(yyyy-MM-dd HH\:mm) LocalHistoryFolderPanel.revertButton.text=Revert + +CTL_SourceTabCaption=&History \ No newline at end of file Index: localhistory/src/org/netbeans/modules/localhistory/ui/view/LocalHistoryTopComponent.java --- localhistory/src/org/netbeans/modules/localhistory/ui/view/LocalHistoryTopComponent.java Base (BASE) +++ localhistory/src/org/netbeans/modules/localhistory/ui/view/LocalHistoryTopComponent.java Locally Modified (Based On LOCAL) @@ -43,25 +43,58 @@ */ package org.netbeans.modules.localhistory.ui.view; +import java.awt.Color; +import java.awt.Dimension; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; import java.io.Serializable; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import org.netbeans.core.spi.multiview.CloseOperationState; +import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.awt.UndoRedo; import org.netbeans.modules.versioning.util.DelegatingUndoRedo; import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.LineBorder; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.modules.localhistory.LocalHistory; +import org.openide.explorer.ExplorerManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataShadow; +import org.openide.nodes.Node; +import org.openide.util.Lookup; /** * Top component which displays something. * * @author Tomas Stupka */ -final public class LocalHistoryTopComponent extends TopComponent { +@MultiViewElement.Registration( + displayName="#CTL_SourceTabCaption", // XXX + iconBase="org/netbeans/modules/java/resources/diff-next.png", // XXX + persistenceType=TopComponent.PERSISTENCE_NEVER, + preferredID="text.history", + mimeType="", + position=2001 +) +final public class LocalHistoryTopComponent extends TopComponent implements MultiViewElement { private static LocalHistoryTopComponent instance; private LocalHistoryFileView masterView; - private static final String PREFERRED_ID = "LocalHistoryTopComponent"; + static final String PREFERRED_ID = "text.history"; private final DelegatingUndoRedo delegatingUndoRedo = new DelegatingUndoRedo(); + private JPanel t; public LocalHistoryTopComponent() { initComponents(); @@ -72,6 +105,55 @@ // setIcon(Utilities.loadImage(ICON_PATH, true)); } + public LocalHistoryTopComponent(Lookup context) { + this(); + DataObject dataObject = context.lookup(DataObject.class); + + List files = new LinkedList(); + if (dataObject instanceof DataShadow) { + dataObject = ((DataShadow) dataObject).getOriginal(); + } + if (dataObject != null) { + Collection doFiles = toFileCollection(dataObject.files()); + files.addAll(doFiles); + } + init(files.toArray(new File[files.size()])); + } + + private Collection toFileCollection(Collection fileObjects) { + Set files = new HashSet(fileObjects.size()*4/3+1); + for (FileObject fo : fileObjects) { + files.add(FileUtil.toFile(fo)); + } + files.remove(null); + return files; + } + + public void init(final File... files) { + final LocalHistoryFileView fileView = new LocalHistoryFileView(); + LocalHistoryDiffView diffView = new LocalHistoryDiffView(this); + fileView.getExplorerManager().addPropertyChangeListener(diffView); + fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { + LocalHistoryTopComponent.this.setActivatedNodes((Node[]) evt.getNewValue()); + } + } + }); + + // XXX should be solved in a more general way - not ony for LocalHistoryFileView + this.masterView = fileView; + splitPane.setTopComponent(masterView.getPanel()); + splitPane.setBottomComponent(diffView.getPanel()); + + LocalHistory.getInstance().getParallelRequestProcessor().post(new Runnable() { + @Override + public void run() { + fileView.refresh(files); + } + }); + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is @@ -95,13 +177,6 @@ private javax.swing.JSplitPane splitPane; // End of variables declaration//GEN-END:variables - public void init(JPanel diffPanel, LocalHistoryFileView masterView) { - // XXX should be solved in a more genarel way - not ony for LocalHistoryFileView - this.masterView = masterView; - splitPane.setTopComponent(masterView.getPanel()); - splitPane.setBottomComponent(diffPanel); - } - public UndoRedo getUndoRedo() { return delegatingUndoRedo; } @@ -146,6 +221,29 @@ return PREFERRED_ID; } + @Override + public JComponent getVisualRepresentation() { + return this; + } + + @Override + public JComponent getToolbarRepresentation() { + if( t == null ) { + t = new JPanel(); + } + return t; + } + + @Override + public void setMultiViewCallback(MultiViewElementCallback callback) { + + } + + @Override + public CloseOperationState canCloseElement() { + return CloseOperationState.STATE_OK; + } + final static class ResolvableHelper implements Serializable { private static final long serialVersionUID = 1L; public Object readResolve() { @@ -153,4 +251,23 @@ } } + @Override + public void componentDeactivated() { + super.componentDeactivated(); } + + @Override + public void componentActivated() { + super.componentActivated(); + } + + @Override + public void componentHidden() { + super.componentHidden(); + } + + @Override + public void componentShowing() { + super.componentShowing(); + } +} Index: localhistory/src/org/netbeans/modules/localhistory/ui/view/ShowLocalHistoryAction.java --- localhistory/src/org/netbeans/modules/localhistory/ui/view/ShowLocalHistoryAction.java Base (BASE) +++ localhistory/src/org/netbeans/modules/localhistory/ui/view/ShowLocalHistoryAction.java Locally Modified (Based On LOCAL) @@ -43,17 +43,30 @@ */ package org.netbeans.modules.localhistory.ui.view; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; +import java.util.Collection; +import java.util.MissingResourceException; import java.util.Set; import javax.swing.SwingUtilities; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.core.api.multiview.MultiViewHandler; +import org.netbeans.core.api.multiview.MultiViewPerspective; +import org.netbeans.core.api.multiview.MultiViews; +import org.netbeans.core.spi.multiview.MultiViewDescription; import org.netbeans.modules.versioning.spi.VCSContext; -import org.openide.explorer.ExplorerManager; +import org.openide.cookies.EditCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.HelpCtx; +import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.actions.NodeAction; +import org.openide.windows.TopComponent; /** * @@ -71,33 +84,98 @@ VCSContext ctx = VCSContext.forNodes(activatedNodes); final Set rootSet = ctx.getRootFiles(); - SwingUtilities.invokeLater(new Runnable() { - public void run() { File[] files = rootSet.toArray(new File[rootSet.size()]); + if(!files[0].isFile()) { + return; + } + + File file = files[0]; + FileObject fo = FileUtil.toFileObject(file); + if(fo != null) { + DataObject dataObject = null; + try { + dataObject = DataObject.find(fo); + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + if(dataObject != null) { + if(findInOpenTC(dataObject)) { + return; + } + if(findInMVDescriptions(dataObject)) { + return; + } + } + } + + // fallback opening a LHTopComponent + openTC(files); + } + + private void openTC(final File[] files) throws MissingResourceException { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { final LocalHistoryTopComponent tc = new LocalHistoryTopComponent(); tc.setName(NbBundle.getMessage(this.getClass(), "CTL_LocalHistoryTopComponent", files[0].getName())); tc.open(); tc.requestActive(); + tc.init(files); + } + }); + } - if(files[0].isFile()) { - LocalHistoryFileView fileView = new LocalHistoryFileView(); - LocalHistoryDiffView diffView = new LocalHistoryDiffView(tc); - fileView.getExplorerManager().addPropertyChangeListener(diffView); - fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { - tc.setActivatedNodes((Node[]) evt.getNewValue()); + /** + * XXX HACK temporary solution to find out if the given dataobject provides a multiview + */ + private boolean findInMVDescriptions(DataObject dataObject) { + String mime = dataObject.getPrimaryFile().getMIMEType(); + Lookup l = MimeLookup.getLookup(MimePath.get(mime)); + Collection descs = l.lookupAll(MultiViewDescription.class); + if (descs.size() > 1) { + // LH is registred for every mimetype, so we need at least two + for (MultiViewDescription desc : descs) { + if (desc.preferredID().equals(LocalHistoryTopComponent.PREFERRED_ID)) { + EditCookie cookie = dataObject.getLookup().lookup(EditCookie.class); + if (cookie != null) { + cookie.edit(); + findInOpenTC(dataObject); + return true; } } - }); - tc.init(diffView.getPanel(), fileView); - fileView.refresh(files); } } - }); + return false; + } + private boolean findInOpenTC(DataObject dataObject) { + Set tcs = TopComponent.getRegistry().getOpened(); + for (final TopComponent tc : tcs) { + Lookup l = tc.getLookup(); + DataObject tcDataObject = l.lookup(DataObject.class); + if (tcDataObject != null && dataObject.equals(tcDataObject)) { + final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); + if (handler != null) { + MultiViewPerspective[] perspectives = handler.getPerspectives(); + for (final MultiViewPerspective p : perspectives) { + if(p.preferredID().equals(LocalHistoryTopComponent.PREFERRED_ID)) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + handler.requestActive(p); + tc.requestActive(); } + }); + break; + } + } + return true; + } + } + } + return false; + } protected boolean enable(Node[] activatedNodes) { if(activatedNodes == null || activatedNodes.length != 1) {