-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NETBEANS-1979] Create Mode from client code #1135
Conversation
Merge upstream
XML String so that a TopComponent may then be programatically docked into that Mode.
Allow any kind of Mode to be created programatically from a ModeConfig XML String so that a TopComponent may then be programatically docked into that Mode. Mark Phipps. mwgphipps@gmail.com mark.phipps@sucfin.com
…ira Issue. Merge branch 'master' of https://github.com/phipma/incubator-netbeans
Merge remote-tracking branch 'upstream/master'
…ending that interface and providing utility helper class.
…ur of extending that interface and providing utility helper class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changes are OK in general. Consider the few suggested changes, increase specification version of the module in manifest.mf
, add @since
tag to refer to that version, and also write an entry into apichanges.xml
to with references to the new API types.
|
||
|
||
/** This class is an implementation of Mode interface. | ||
* It designates 'place' on screen, at wich TopComponent can occure. | ||
* | ||
* @author Peter Zavadsky | ||
*/ | ||
public final class ModeImpl implements Mode { | ||
public final class ModeImpl implements Mode.Xml { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, Mode.Xml
sounds like a good way to extend the existing interface.
@@ -48,7 +50,7 @@ | |||
* @author Peter Zavadsky | |||
*/ | |||
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.WindowManager.class) | |||
public final class WindowManagerImpl extends WindowManager implements Workspace { | |||
public final class WindowManagerImpl extends WindowManager implements Workspace, WindowManager.ModeManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike Mode
, WindowManager
is abstract class - e.g. the methods could be added to it. They would just need some default implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving methods back into WindowManager from ModeUtilities.
@@ -1364,6 +1363,16 @@ public static String escapeTcId4XmlContent (String tcName) { | |||
} | |||
return tcName; | |||
} | |||
|
|||
public ModeConfig createModeFromXml(String xml) throws IOException { | |||
ModeParser modeParser = ModeParser.parseFromString("NO_NAME_YET", new HashSet(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to add // NOI18N
to mark strings that shouldn't be translated. Having them in some static final String
constant would be even better, especially when used sever times.
new HashSet(1)
seems strange. Such size cannot even access a single element (as the ratio is 0.75
by default and 1 * 0.75 < 1
), is that what you wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied HashSet(1)
from the original code in WindowManagerParser:
/**
* Loads Mode configuration from the given file.
* @param fo
* @return
* @throws IOException
* @since 2.70
*/
public static ModeConfig loadModeConfigFrom( FileObject fo ) throws IOException {
String modeName = fo.getName();
ModeParser parser = new ModeParser(modeName, new HashSet(1));
parser.setInLocalFolder(true);
parser.setLocalParentFolder(fo.getParent());
return parser.load();
}
That was the only occurrence of calling that ctor without a Set of TopComponent names I think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing to static final and default HashSet ctor.
* | ||
* @author Mark Phipps | ||
*/ | ||
public class ModeManagerTest extends NbTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this looks like a test that tests something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed name to WindowManagerModeTest.
// Remove unwanted Modes. | ||
for (Mode mode: wm.getModes()) { | ||
if (mode.getName().startsWith("anonymous")) { | ||
ModeUtility.removeMode(wm, mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModeUtility
!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will just be wm.removeMode(mode);
* @see http://wiki.apidesign.org/wiki/ExtendingInterfaces | ||
* | ||
* @author Mark Phipps | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to go this path of static utility helper method class, then I'd suggest to use ModeUtilities
name. And again @since
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming to ModeUtilities.
* @param windowManager typically WindowManager.getDefault() | ||
* @param xml the XML that was originally produced by {@link #toXml} | ||
*/ | ||
public final static void createModeFromXml(WindowManager windowManager, String xml) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange parameters. I'd expect the method to call WindowManager.getDefault()
itself.
Shouldn't the method return Mode
or null
? How can one distinguish between success and failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - Changing to better indicate success or failure.
* @param mode the {@link Mode} to remove | ||
* @return success if the Mode can no longer be found in the Window Manager | ||
*/ | ||
public final static boolean removeMode(WindowManager windowManager, Mode mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Mode.Xml.remove()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interface - not sure what you mean...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is an interface, but a newly defined one. E.g. it is possible to put new methods into it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but at the point of removing a Mode from the WindowManager, there is no XML in play.
A Mode doesn't have to be an instance of Mode.XML to be removed. As far as I can see all Modes are ModeImpls anyway, which are defined with XML and the Mode.XML interface and ModeUtilities class provides the non-breaking-api way of accessing that.
Now I implemented the remove(), updateConstraints() and createMode() methods as abstract methods of WindowManager as you suggested.
Maybe you can judge these changes on my next push?
* @param windowManager typically WindowManager.getDefault() | ||
* @param xml the XML that was originally produced by {@link #toXml} | ||
*/ | ||
public final static void updateModeConstraintsFromXml(WindowManager windowManager, String xml) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Mode.Xml.updateConstraints(String)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise your previous comment.
* Modes directly. | ||
* | ||
* @see ModeXml | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @since
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jaroslav,
What should I change the version to? Currently manifest contents are:
Manifest-Version: 1.0
OpenIDE-Module: org.openide.windows
OpenIDE-Module-Specification-Version: 6.80
OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties
AutoUpdate-Essential-Module: true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing it to 6.81 Hope that's correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore. The current version is 6.81
. You need to add something - at least 6.82
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - changed to 6.82 just now.
Thanks @JaroslavTulach I will make the changes you suggest as soon as I have time. |
Just added WIP label until the requested changes arrive. |
Better indication of success or failure of Mode operations, rename ModeUtility to ModeUtilities, use abstract methods in WindowManager, update manifest.mf with 6.81, update apichanges.xml, add @SInCE tags.
Changes pushed, please check. |
Hi @JaroslavTulach , @lkishalmi, I can't change the work-in-progress label myself - don't know what to do to prompt a review of these latest changes, but they are ready when you are... |
Hi Fellas, @geertjanw @JaroslavTulach @lkishalmi do you have scope to progress this PR at all? Should I be doing something...? |
Is there anything from your point of view that needs to be done? How confident are you of this one? |
Removed that label, if it helps. |
All done as far as I am concerned, I was hoping Jaroslav would review again and confirm "OpenIDE-Module-Specification-Version: 6.80" |
Sorry, I mean "OpenIDE-Module-Specification-Version: 6.81" |
Hi Mark, awesome work, and what do you think re iCLA, i.e., see this discussion: |
Maybe, we should squash and merge. |
Ideally, @phipma would send in an iCLA first, just need to hear from him how he feels about that. |
Yes :) I don't think that we should merge this PR as it is. So, I think @phipma should rebase and squash himself then push(force) it if possible ;) |
I have sent the ICLA. My git skills are limited - I did a squash before, but not rebase... Can someone outline the steps I should take please? |
Great! @phipma If you accept that we merge your changes as ONE commit, we can do that via the "Squash and merge" button. Otherwise, you should squash your changes properly yourself. (e.g. see https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History) |
Please go ahead and use the "squash and merge" button! Let's just get this done! |
@phipma OK, thank you! BTW, did you look at this? #1135 (comment) @geertjanw Let's squash and merge if there is no problem after the iCLA is accepted :) |
…-netbeans into Create_Mode
…eans into Create_Mode
Hi @geertjanw, @junichi11 my ICLA was accepted last week, so is there anything else I need to do before you can squash and merge? Let me know if there is, thanks. |
@@ -1531,7 +1595,7 @@ public void run() { | |||
if (IDESettings.isGui()) { | |||
// running in GUI mode, but | |||
if (!WindowManagerImpl.getInstance().isVisible()) { | |||
// window manager isn't yet visible => exit for now | |||
// window manager isn't yet visible => exit for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove whitespaces.
* @return All the known modes in the XML configuration that they would | ||
* be saved to disk as. | ||
* @throws IOException | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, the below is better. (*
positions)
/** Extract all ModeConfigs in XML.
*
* @param wmc
* @return All the known modes in the XML configuration that they would
* be saved to disk as.
* @throws IOException
*/
} | ||
|
||
private void writeGroups (WindowManagerConfig wmc) throws IOException { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove whitespaces.
@phipma I'm not sure about this area. So I've just had a look at formatting. Please have a look at the comments. I'm going to merge this later because @JaroslavTulach has already approved this PR. |
I've confirmed that "Mark Phipps" exists in http://people.apache.org/unlistedclas.html. |
@phipma BTW, we should fix the commit message when we squash & merge via the button. Your commit messages are used as a list by default. e.g.
Commit message title is this PR one, maybe. So, please let us know the commit message you expect. Thanks! |
@junichi11 I have made the changes you suggested: removed white space and reformatted comments. So please use that when you squash and merge. |
@phipma Merged. Thank you for your contribution! |
Allow any kind of Mode to be created programatically from a ModeConfig XML String so that a TopComponent may then be programatically docked into that Mode.
I have backed out the incompatible API changes and added a ModeUtility class following the advice from @JaroslavTulach. I hope this is better...?
Kind regards
Mark Phipps